![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to search and replace text in same file | Vrgurav | Shell Programming and Scripting | 1 | 04-25-2008 03:20 AM |
| automating file search and replace text | ommatidia | Shell Programming and Scripting | 3 | 02-28-2008 01:40 PM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 07:24 AM |
| search and replace the whole line | Jartan | Shell Programming and Scripting | 17 | 09-25-2007 10:58 AM |
| How do you search and replace a text with markerA that end with markerB | drone | Shell Programming and Scripting | 1 | 06-19-2003 06:12 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Search and replace multi-line text in files
Hello
I need to search for a mult-line text in a file exfile1 and replace that text with another text. The text to search for is in exfile2 and the replacement text is in exfile3. I work with kornshell under AIX and need to do this with a lot of files. (the file type is postscript and they need to be edited before printing with our old card plotter that cannot manage bitmaps) exfile1: asdasdasdasd asdasdasdasd abc def ghi sdasdasdasda asdasdasdada exfile2: abc def ghi exfile3: jkl mno pqr I have tried with sed with little sucess. Any ideas? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You can't use sed because its processing is line-based. You can use awk if you unset the record separator, like this...
Code:
awk ' BEGIN { RS="" }
FILENAME==ARGV[1] { s=$0 }
FILENAME==ARGV[2] { r=$0 }
FILENAME==ARGV[3] { sub(s,r) ; print }
' exfile2 exfile3 exfile1 > exfile4
Code:
asdasdasdasd asdasdasdasd jkl mno pqr sdasdasdasda asdasdasdada |
|
#3
|
|||
|
|||
|
Thank you very much for the solution.
Works great! |
|
#4
|
|||
|
|||
|
I have tested a little more and I have a problem.
All the files are bigger than 10,239 bytes and cannot be processed by the awk function. Error: "awk: 0602-534 Input line xxxxxxxx cannot be longer than 10,239 bytes." Any idea to solve this problem? Best regards marz |
|
#5
|
|||
|
|||
|
I am doing awk on file size of 84461608 bytes without
any trouble . Can you please expalin what all you are doing on that ? |
|
#6
|
||||
|
||||
|
Quote:
1. Working on a different platform 2. You are woking with gnu awk, the OP is not. |
|
#7
|
||||
|
||||
|
My guess is that he is not using RS="" and his file does not contain a line with more than 10,239 bytes.
|
||||
| Google The UNIX and Linux Forums |