LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-09-2006, 03:50 AM   #1
Fond_of_Opensource
Member
 
Registered: May 2006
Posts: 55

Rep: Reputation: 15
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.
 
Old 11-09-2006, 03:57 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 10:54 PM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 09:45 PM
sed doesn't accept $variable in bash script chii-chan Programming 6 05-28-2005 07:07 AM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 07:54 PM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 05:17 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration