LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 02-09-2004, 09:38 AM   #1
linuxdev
Member
 
Registered: Feb 2004
Posts: 34

Rep: Reputation: 15
sed Command


HI

I want to change the value of one variable in a file1.
I have a script where I am trying to use "sed" command to
change the value of that variable in file1.

BUT it doesn't seem to work...I am using

sed 's/linux-2.4/newlinux-2.4/' file1 (This is present in my script)

here I want linux-2.4 to be replaced my newlinux-2.4 in
file1.

Any insights into this ...where I might be wrong....

Thanks!
 
Old 02-09-2004, 10:25 AM   #2
nikai
LQ Newbie
 
Registered: Dec 2003
Location: Kitzbühel, Austria
Distribution: Gentoo
Posts: 23

Rep: Reputation: 15
If you want to overwrite the file, use the "-i" (in-place) option.
Then, your expression only catches the first occurence of the search term in every line.
For catching all of them, use "s///g".
So this would be: (untested)

sed -i -e 's/linux-2.4/newlinux-2.4/g' file1
 
Old 02-09-2004, 10:42 AM   #3
linuxdev
Member
 
Registered: Feb 2004
Posts: 34

Original Poster
Rep: Reputation: 15
How can I store the value of system date in some variable and use that value in my script...

I tired
var=date;
echo $date( in my script)

I know something is wrong here but how can I get the date in some variable ....
and once I get the date in some variable...I want to concantenate that value with some
string in my script....
 
Old 02-09-2004, 11:27 AM   #4
nikai
LQ Newbie
 
Registered: Dec 2003
Location: Kitzbühel, Austria
Distribution: Gentoo
Posts: 23

Rep: Reputation: 15
You can expand commands like this:

echo `date`

or

echo $(date)

the same with a variable:

DATE=`date`
echo $DATE

concatenation:

echo $DATE" and "$DATE
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command Kalyani1 Linux - Software 28 12-07-2005 11:48 AM
sed command rharris72 Programming 6 11-20-2005 08:26 PM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM
sed command linuxdev Linux - Newbie 9 02-24-2004 04:50 PM
sed command kwigibo Linux - General 3 04-21-2002 04:11 PM


All times are GMT -5. The time now is 04:32 PM.

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