LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2012, 04:46 AM   #1
ksvinaykumar
LQ Newbie
 
Registered: Apr 2012
Posts: 9

Rep: Reputation: Disabled
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.
 
Old 04-10-2012, 05:58 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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?
 
1 members found this post helpful.
Old 04-10-2012, 07:20 AM   #3
ksvinaykumar
LQ Newbie
 
Registered: Apr 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thank u so much. It worked.

Regards, Raje.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compare second column of a file then print the first column of it in a ne fil if true java_girl Linux - Newbie 2 03-16-2012 05:50 AM
[SOLVED] Read a number x from a file and write a character in the xth column of other file homexylo Programming 7 08-05-2011 06:28 AM
[SOLVED] Insert a column of text to a text file docaia Linux - Newbie 5 06-02-2011 11:55 AM
Insert a column from 1 file into a 2nd file ozmj73 Linux - Newbie 3 05-28-2011 01:32 PM
Read text file column by column RVF16 Programming 11 05-31-2009 08:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration