Search and replace multi-line text in files Ygor - Shell Programming and Scripting - Unix Linux Forums

  Go Back    



Search and replace multi-line text in files

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member Ygor Regarding:
Search and replace multi-line text in files.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old 10-06-2005
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 2 May 2014, 7:14 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 112 Times in 98 Posts
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