![]() |
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 |
| Adding Multiple Lines to Multiple Files | dayinthelife | Shell Programming and Scripting | 2 | 06-04-2008 12:50 PM |
| Replace text in multiple files | on9west | Shell Programming and Scripting | 1 | 05-20-2008 02:35 AM |
| Replace text in multiple files | Tonka52 | Shell Programming and Scripting | 10 | 03-24-2008 08:11 AM |
| Find and replace a string in multiple files | pharos467 | UNIX for Dummies Questions & Answers | 2 | 11-05-2007 11:47 PM |
| using sed command to replace multiple lines | radha.kalivar | Shell Programming and Scripting | 1 | 07-10-2007 11:36 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How can I replace multiple lines from different files
Suppose i have two files
file1.txt Name : Raju Address:rt8pouououoiu City:tyretyeuetu file2.txt Address :28a The line "address:28a" in file2 has to get replaced in the address line of file1 .. The output should be Name :Raju Address:28a city :tyretyeuetu Please help me on this |
|
||||
|
I'm sure the real (n)awk experts have a better solution.
nawk '/^Name[ ]*:/ { NAM=$0 }; /^Address[ ]*:/ { ADDR=$0 }; /^City[ ]*:/ { print NAM"|"ADDR"|"$0 }' file1.txt | paste -d"|" - file2.txt | nawk '{ FS="|" } { print $1; print $4; print $3 }' |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|