Results 1 to 5 of 5
Hi all,
I have two files, where one file is already having some changes.
and i want to incorporate same changes into another file.
So,I need to write one script, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-04-2013 #1Just Joined!
- Join Date
- Feb 2013
- Posts
- 3
sed/awk scripting help to edit files automatically.
Hi all,
I have two files, where one file is already having some changes.
and i want to incorporate same changes into another file.
So,I need to write one script, which
will do following steps sequentially:
search for specific pattern in a given file, and search the same pattern in another file, and finally copy the text found after 2 lines of searched pattern in first file into second file after 2 lines of the searched pattern.
so, if it is possible with sed/awk scripting, pls help me out..
Thanks
- 02-06-2013 #2Just Joined!
- Join Date
- Sep 2007
- Posts
- 19
- 02-06-2013 #3Just Joined!
- Join Date
- Feb 2013
- Posts
- 3
Hi,
for example:
file1.txt : f
-----------
hello praveen,
how r u...
now we need to test this..
ok fine ...!!
hello santosh,
how r u...
now we need to test this..
ok fine ...!!
hello pranesh,
how r u...
now we need to test this..
ok fine ...!!
file2.txt :
----------------------
hello praveen,
how r u...
now what we have to do..
ok fine ...!!
hello raghunath,
how r u...
now what we have to do..
ok fine ...!!
hello pranesh,
how r u...
now what we have to do..
ok fine ...!!
Now i want file2.txt to be changed to as shown below:
hello praveen,
how r u...
now we need to test this..
ok fine ...!!
hello raghunath,
how r u...
now what we have to do..
ok fine ...!!
hello pranesh,
how r u...
now what we have to do..
ok fine ...!!
---------------------------------------------------
Means i need to search for pattern "praveen" in file1.txt and file2.txt,
and copy contents of 2nd line after pattern "praveen" in file1.txt to file2.txt
Thanks
- 02-06-2013 #4Just Joined!
- Join Date
- Sep 2007
- Posts
- 19
Ok. I'm not sure if your example was so good. There were 3 common strings (1) hello XYZ (2) how r u and (3) ok fine ...!!
I think I can understand what you are trying to do. sed/grep will not help AFAIK. Try using gawk/perl. In gawk you can read both files for one pattern. Then start transferring as many lines as you want from one to other. Then move on to the next pattern. Not easy though. It'll take some time in gawk. Python or Perl or maybe even C(!!), might be faster.
I'd suggest do one pattern at a time. Run a shell script to complete for all patterns.Last edited by tpb261; 02-06-2013 at 01:50 PM. Reason: :oops: Stupid thing to try to quote the entire message
- 02-07-2013 #5Just Joined!
- Join Date
- Feb 2013
- Posts
- 3
Yes, you understood correctly. Thanks for giving proper direction..


1Likes
Reply With Quote

