![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
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 06:57 AM |
| SED to replace file content | godfreyyip | Shell Programming and Scripting | 6 | 09-04-2009 06:24 AM |
| Perl search and replace file content. | jxh461 | Shell Programming and Scripting | 3 | 04-16-2009 11:26 PM |
| replace a string with content from another file | afatguy | Shell Programming and Scripting | 4 | 09-14-2006 09:25 PM |
| How to replace a variable content | josephwong | Shell Programming and Scripting | 4 | 06-25-2006 11:18 PM |
![]() |
|
|
LinkBack | 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 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 |
| 5 Days Ago | 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 |
|
|