LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed Command (https://www.linuxquestions.org/questions/linux-newbie-8/sed-command-144044/)

linuxdev 02-09-2004 09:38 AM

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!

nikai 02-09-2004 10:25 AM

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

linuxdev 02-09-2004 10:42 AM

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....

nikai 02-09-2004 11:27 AM

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


All times are GMT -5. The time now is 11:43 PM.