-   Linux - General (
-   -   Using sed command (

ahsanpmd 02-21-2013 05:50 AM

Using sed command
I want to replace ydate_ini='2013022000' with ydate_ini='$DATE00' (where DATE is system's date) in a file using sed.

Tried cat INPUT | sed "s/^.ydate_ini.*$/ ydate_ini='$DATE00'/" >

but now working.

chrism01 02-21-2013 06:52 AM


# create date
 t=`date +%Y%m%d`
 echo $t

 cat t.t

 sed -i -e "s:^ydate_ini.*:ydate_ini='${t}00':" t.t
 cat t.t

-i flag does in-place replacement, so backup the file first.

ahsanpmd 02-21-2013 07:56 AM

Thanks chris atually I was making a mistake in my command , thanks For your help too

ahsanpmd 02-21-2013 11:11 PM

Your command not working Chris
In my file INPUT there is line ydate_ini='2013022000', ydate_bd='2013022000',
I have to change both ydate_ini and ydate_bd with current date. Your command isn't making any effect.However I have used
cat INPUT | sed "s/^.*ydate_ini=.*$/ ydate_ini='$DAY'/" >
It changes ydate_ini to current date but it omit the next portion of the line i.e ydate_bd='2013022000',

ahsanpmd 02-21-2013 11:23 PM

it worked
cat INPUT | sed "s/^.*ydate_ini=.*$/ ydate_ini='$DAY', ydate_bd='$DAY',/" >

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