Tuesday, 15 July 2014

bash - Cut command including a space which is confusing head command? -



bash - Cut command including a space which is confusing head command? -

i trying utilize output of cutting command head command output specific line. find if number beingness fed head command 10+ works fine. wondering if cutting -c1-2 including white space single digits tripping head command?

my code

#!/bin/bash echo "enter name" read input cutting -c5-19 filelist | grep -n "$input" | cutting -c1-2 > cat while read cat head -$cat filelist | tail -1 > filelist2 done < cat

any advice or suggestions appreciated! give thanks :) edit

fullranjit singh marketing eagles dean johnson fullken whillans marketing eagles karen thompson partpeter robertsonsales golden tigersrich gardener contsandeep jain president wimps ken whillans partjohn thompson operations hawks cher contcher operations vegans karen patel fulljohn jacobs sales hawks davinder singh fulldean johnson finance vegans sandeep jain partkaren thompson engineeringvegans john thompson fullrich gardener golden tigerspeter robertson fullkaren patel wimps ranjit singh

this 'filelist' error getting "head: invalid trailing alternative -- :" if type in 'patel' name, works.

answer revised question

replace:

cut -c5-19 filelist | grep -n "$input" | cutting -c1-2 > cat

with:

cut -c5-19 filelist | grep -n "$input" | cutting -d: -f1 >cat

grep -n places colon between line number , text of line. so, natural utilize colon field delimiter cut , inquire cutting homecoming first field.

from have shown, script can farther simplified to:

read -p "enter name: " input linenum=$(cut -c5-19 filelist | grep -n "$input" | cutting -d: -f1) head -$linenum filelist | tail -1 > filelist2 answer original question

since haven't shown filelist, can guess @ problem. if right filelist containing spaces, solution. replace:

head -$cat filelist | tail -1 > filelist2

with:

head -${cat## } filelist | tail -1 > filelist2

the construction ${cat## } removes leading spaces varialbe cat.

bash loops unix cut head

No comments:

Post a Comment