LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Extract a column from file 1 and insert in file 2 (https://www.linuxquestions.org/questions/linux-newbie-8/extract-a-column-from-file-1-and-insert-in-file-2-a-939041/)

ksvinaykumar 04-10-2012 03:46 AM

Extract a column from file 1 and insert in file 2
 
I want to extract the column9 from file1 and insert in between the columns 10 & 11 of file2.

How to do this using awk. Pls reply with syntax.


Thanks and regards, Raje.

colucix 04-10-2012 04:58 AM

What have you tried so far? You can pass both files to awk, do something when awk reads the first one (check the expression FNR == NR) and something else when awk reads the second one (check FNR < NR). Example:
Code:

awk 'FNR==NR{field[NR]=$9}; FNR<NR{$10=($10 FS field[FNR]); print}' file1 file2
Is this what you're looking for?

ksvinaykumar 04-10-2012 06:20 AM

Thank u so much. It worked.

Regards, Raje.


All times are GMT -5. The time now is 01:00 AM.