How can I replace multiple lines from different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I replace multiple lines from different files
# 1  
Old 02-07-2007
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  
Old 02-07-2007
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  
Old 02-07-2007
Try...
Code:
awk '/Address:/{getline < "file2.txt"}{print}' file1.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string with multiple lines

Hello Guys, I need to replace a string with multiple lines. For eg:- ABC,DEF,GHI,JKL,MNO,PQR,STU need to convert the above as below:- ABC,DEF, GHI1 GHI2 GHI3, JKL,MNO, PQR1 PQR2 PQR3, STU i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies

2. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

3. Shell Programming and Scripting

Replace multiple lines through sed

Hi All, I have a input file as sample below <this is not starting of file> record line1 line2 line3 end line4 line5 record line6 line7 line8 my requirement is this, i want to select a pattern between first record and end, whatever is written between first record and end. and... (0 Replies)
Discussion started by: adgangwar
0 Replies

4. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

5. Shell Programming and Scripting

Find and replace multiple lines

I have a section of text in file A, see below # falkdjf lkjadf lkjadf lkajdf lkajdf lkajdf lkjadf lkjadf 234.234.2.234 lkjlkjlk 234.234.3.234 # Only the first line with "# falkdjf lkjadf lkjadf" is unique in the file. The new section that I want to overwrite the old section above is in... (1 Reply)
Discussion started by: jyang72211
1 Replies

6. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

Replace multiple lines between tags using sed

I have a file example.txt with content look like this: <TAG> 1 2 3 </TAG> and I use a sed command to replace everything between <TAG></TAG> as below: sed -e 's/\(<TAG>\)*\(<.*\)/something/g' example.txt > example.txt.new But unfortunately, the command failed to replace as i want, it... (23 Replies)
Discussion started by: dollylamb
23 Replies

8. Shell Programming and Scripting

replace multiple lines in multiple files

i have to search a string and replace with multiple lines. example Input echo 'sample text' echo 'college days' output echo 'sample text' echo 'information on students' echo 'emp number' echo 'holidays' i have to search a word college and replace the multiple lines i have... (1 Reply)
Discussion started by: unihp1
1 Replies

9. Shell Programming and Scripting

replace multiple lines in file

Hello I am a beginner in shell script. I was trying to find a way to replace multiple lines of a file with different set of multiple line. sed -n '/begin/,/end/p' < sample1.txt >test.txt UNEDITED=`cat test.txt` vi test.txt EDITED=`cat test.txt`... (2 Replies)
Discussion started by: nox
2 Replies

10. Shell Programming and Scripting

using sed command to replace multiple lines

the file contains the follwoing lines /* * Copyright (C) 1995-1996 by XXX Corporation. This program * contains proprietary and confidential information. All rights reserved * except as may be permitted by prior written consent. * * $Id: xxx_err.h,v 1.10 2001/07/26 18:48:34 zzzz $ ... (1 Reply)
Discussion started by: radha.kalivar
1 Replies
Login or Register to Ask a Question