Find Replace Help

New to change change 10 to 45 its a first line in the file.

"15/10/2009 00:00:00"|DATA|NEW

New to change change 10 to 45 its a first line in the file.

"15/10/2009 00:00:00"|DATA|NEW

you mean to say if the line has 10 then u want to change to 45.

if ur 1st line is "10/10/2010 10:10:10"|DATA|NEW
then the output like
45/45/2045 45:45:45|DATA|NEW ... is it like this? Also pls tell ur 1st date time stamp is in between double quotes in the file?

no it should be
15/45/2009 00:00:00"|DATA|NEW

and this needs to be done on all lines.

t.txt file contains the line which we want to change.

sed 's/\/10\//\/45\//g' t.txt > temp.txt
mv temp.txt t.txt

Thanks
Sarwan

But this might change if there are any further occurence of 10 on same line i only need to be done on first word

As Sarwan says:

sed 's/\/10\//\/45\//' t.txt > temp.txt
mv temp.txt t.txt

I have removed "g" option.

What if the text i want to replace is dynamic say 10+1 need to add 1

I think you have to write shell script for this.

something like this,

$ cat t.txt
15/10/2009 00:00:00"|DATA|NEW

$ cat se.sh
#! /bin/sh

a=10
let b=$a+1
sed -i "s/$a/$b/1" t.txt

$ cat t.txt
15/11/2009 00:00:00"|DATA|NEW

sed -i does not work at my end

Try this....

$ cat t.txt
15/10/2009 00:00:00"|DATA|NEW

$ cat se.sh
#! /bin/sh

a=10
let b=$a+1
sed "s/$a/$b/1" t.txt > temp.txt
mv temp.txt t.txt

$ cat t.txt
15/11/2009 00:00:00"|DATA|NEW

awk 'BEGIN{FS=OFS="/"}NR==1{$2++}1'  file > newfile && mv newfile file

:wink: