mwrg
November 15, 2009, 10:52am
1
Hi
I have a control file which looks like this
LOAD DATA
INFILE '/home/scott/XXX.dat'
PRESERVE BLANKS
.............
.............
how can i change the content of this file and replace the file in the second line with anothe file name and write it back with another name to the disk?
Thanks
Scott
November 15, 2009, 11:03am
2
sed "2s@.*@INFILE 'newfile'@" infile > outfile
mwrg
November 15, 2009, 1:54pm
3
Thanks buddy one more thing. How can i add a new line before the third line (Which is PRESERVE BLANKS) so the new file will look like this
LOAD DATA
INFILE '/home/scott/XXX.dat'
<New Line>
PRESERVE BLANKS
.............
.............
Scott
November 15, 2009, 2:36pm
4
sed "/INFILE/s@.*@INFILE 'newfile/etc'@;/^PRES/i\ " infile > outfile
Or if you meant <New Line> to be a literal string:
sed "/INFILE/s@.*@INFILE 'newfile/etc'@;/^PRES/i<New Line>" infile > outfile
sed "s#^\(INFILE\).*#\1 '/path/to/newfile'\n#" infile > outfile