LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   "shell script :- urgently require help" (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-urgently-require-help-670510/)

feelamit 09-17-2008 08:39 AM

"shell script :- urgently require help"
 
hello everyone,

i have to read a data from a flat file based on some line number, when the line number is known to me.
so i can write command such as :-

b=`sed -n -e 10p /util/xfer/trsfers/TL_MONTH1.csv`

but suppose if i want to use same command inside some loop like this

b=`sed -n -e $var /util/xfer/trsfers/TL_MONTH1.csv`
where var=row number.

this will not work why??
is it because "sed" reads data at one shot.??

can u please advise me how can i read the data inside a loop from different file based on row number.??

i badly require this .

thanks in advance

regards

Uncle_Theodore 09-17-2008 08:52 AM

var=10
sed -n -e "$var"p /util/xfer/trsfers/TL_MONTH1.csv

should work.

David the H. 09-17-2008 08:52 AM

Try quoting the variable. Also, you need the 'p' after it, unless it's included in the variable contents, that is. This worked for me:
Code:

b=`sed -n -e "$var"p /util/xfer/trsfers/TL_MONTH1.csv`
It didn't work without quotes for me either, but I honestly couldn't tell you why.


All times are GMT -5. The time now is 07:58 PM.