LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   storing output of sed in a variable in shell script (https://www.linuxquestions.org/questions/linux-newbie-8/storing-output-of-sed-in-a-variable-in-shell-script-499997/)

Fond_of_Opensource 11-09-2006 04:50 AM

storing output of sed in a variable in shell script
 
Hi friends,

How to store output of sed command in a variable in shell script???

I tried:

1. ls -l >filenames
2. var=`sed -n '5p' filenames` #5th line of the file
3. echo $var

It is not working.

Please help..........

Thanks in advance.

matthewg42 11-09-2006 04:57 AM

Code:

$ cat file.txt
this is line 1 of file.txt
this is line 2 of file.txt
this is line 3 of file.txt
$ var=`sed -n '2p' file.txt`
$ echo $var
this is line 2 of file.txt

Seems to work ok to me. Perhaps your ls -l command doesn't produce 5 lines?


All times are GMT -5. The time now is 04:46 AM.