Results 1 to 2 of 2
Hi all,
I have two files, where the 1. file has special lines that need to be updated by lines from a 2. file:
file1:
foo
foo
foo 0.00 0.00 ...
- 04-12-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 6
Replacing lines with pattern partialy by different file
Hi all,
I have two files, where the 1. file has special lines that need to be updated by lines from a 2. file:
file1:
file2:foo
foo
foo 0.00 0.00 0.00 pattern
foo
foo 1.00 1.00 1.00 pattern
foo
The last three columns of each line containing a"pattern" in file1 must be replaced by three columns of the corresponding line in file2. The result would be:2.00 2.00 2.00
3.00 3.00 3.00
file1:
I found already how to delete a complete line with a "pattern":foo
foo 2.00 2.00 2.00 keyword
foo
foo 3.00 3.00 3.00 keyword
foo
But here I need to delete only the last three columns of a matched line. Is it possible to combine sed and awk to achieve this?Code:sed "/pattern/d" file1
- 04-14-2010 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Something like:
Code:awk '/pattern/{getline s < "file2"; $0=$1 FS s FS k}1' k="keyword" file1 > newfile


Reply With Quote