![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|||
|
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 thisLOAD DATA INFILE '/home/scott/XXX.dat' <New Line> PRESERVE BLANKS ............. ............. |
|
|||
|
Code:
sed "/INFILE/s@.*@INFILE 'newfile/etc'@;/^PRES/i\ " infile > outfile Or if you meant <New Line> to be a literal string: Code:
sed "/INFILE/s@.*@INFILE 'newfile/etc'@;/^PRES/i<New Line>" infile > outfile |
| Bits Awarded / Charged to scottn for this Post | |||
| Date | User | Comment | Amount |
| 11-15-2009 | Scrutinizer | I like the "i\ " | 500 |
|
|||
|
Code:
sed "s#^\(INFILE\).*#\1 '/path/to/newfile'\n#" infile > outfile |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep a pattern and replace a value in it and write to the same file. | yesmani | Shell Programming and Scripting | 6 | 09-11-2009 07:57 AM |
| SED to replace file content | godfreyyip | Shell Programming and Scripting | 6 | 09-04-2009 07:24 AM |
| Perl search and replace file content. | jxh461 | Shell Programming and Scripting | 3 | 04-17-2009 12:26 AM |
| replace a string with content from another file | afatguy | Shell Programming and Scripting | 4 | 09-14-2006 10:25 PM |
| How to replace a variable content | josephwong | Shell Programming and Scripting | 4 | 06-26-2006 12:18 AM |