The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-06-2005
Registered User
 

Join Date: Oct 2005
Posts: 5
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?
Reply With Quote
Forum Sponsor
  #2  
Old 10-06-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
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
..which gives...
Code:
asdasdasdasd
asdasdasdasd
jkl
mno
pqr
sdasdasdasda
asdasdasdada
Reply With Quote
  #3  
Old 10-06-2005
Registered User
 

Join Date: Oct 2005
Posts: 5
Thank you very much for the solution.

Works great!
Reply With Quote
  #4  
Old 10-07-2005
Registered User
 

Join Date: Oct 2005
Posts: 5
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
Reply With Quote
  #5  
Old 10-07-2005
Registered User
 

Join Date: Sep 2005
Posts: 36
I am doing awk on file size of 84461608 bytes without
any trouble . Can you please expalin what all you are doing on that ?
Reply With Quote
  #6  
Old 10-07-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,589
Quote:
Originally Posted by akrathi
I am doing awk on file size of 84461608 bytes without
any trouble
My guess is that you are:
1. Working on a different platform
2. You are woking with gnu awk, the OP is not.
Reply With Quote
  #7  
Old 10-07-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
My guess is that he is not using RS="" and his file does not contain a line with more than 10,239 bytes.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0