![]() |
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 |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|