The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2007
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
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
  #2 (permalink)  
Old 02-07-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
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 }'
  #3 (permalink)  
Old 02-07-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...
Code:
awk '/Address:/{getline < "file2.txt"}{print}' file1.txt
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0