How to replace some content of a file and write with a new name

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

sed "2s@.*@INFILE 'newfile'@" infile > outfile

Thanks buddy :slight_smile: 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
.............
.............

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

:b: Thanks buddy :slight_smile:

sed "s#^\(INFILE\).*#\1 '/path/to/newfile'\n#" infile > outfile