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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 06:11 AM
grep -f file1 file2 vijay_0209 Shell Programming and Scripting 7 03-05-2009 05:48 AM
awk/sed search lines in file1 matching columns in file2 floripoint Shell Programming and Scripting 1 12-17-2008 11:36 PM
Replace specific columns jisha Shell Programming and Scripting 2 10-13-2008 09:34 AM
How can i replace certain columns in the file mani_um Shell Programming and Scripting 6 06-22-2007 10:40 AM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-22-2009
seijihiko seijihiko is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 2
Replace columns from File1 with columns from File2

Hi all,

I would like to replace some columns from file1 with columns from file2. Currently, I'm able to do it with the following command:


awk 'NR==FNR{a[NR]=$1;b[NR]=$2;c[NR]=$3;next;}
{$2=a[FNR];$4=b[FNR];$5=c[FNR];print}' file2 file1 > temp
mv -f temp file1


First, i make the changes and save it as a temp file. Then, i replace file1 with the temp file.
Is there any way i can write the changes to file1 directly without storing it in a temp file first.
How can i perform the same operation using sed?
Pls advice.
Thanks and Regards.

Example:
--------
File 1:
LAYOUT Label TEXT x1 x2 46 10 FOLLI018ULL
LAYOUT Label TEXT x1 x2 46 10 FOLLI018ULL
LAYOUT Label TEXT x1 x2 46 10 FOLLI018ULL
LAYOUT Label TEXT x1 x2 46 10 FOLLI018ULL
LAYOUT Label TEXT x1 x2 46 10 FOLLI018ULL

File 2:
V1 10 20
V5 100 20
V7 50 20
V15 20 50
V20 50 100

Output File 1:
LAYOUT V1 TEXT 10 20 46 10 FOLLI018ULL
LAYOUT V5 TEXT 100 20 46 10 FOLLI018ULL
LAYOUT V7 TEXT 50 20 46 10 FOLLI018ULL
LAYOUT V15 TEXT 20 50 46 10 FOLLI018ULL
LAYOUT V20 TEXT 50 100 46 10 FOLLI018ULL
 

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 02:57 PM.


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