LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 05-28-2011, 11:17 AM   #1
ozmj73
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: Disabled
Thumbs up Insert a column from 1 file into a 2nd file


Hi, I'm trying to copy a column from one file and insert it into another file

e.g.
file1
col1 col2 col3 col4 col5 col6 col7 col8...coln
file2
col1 col2 col3 col4 col5 col6 col7 col8...coln-1

How do I copy col6 from file1 and insert it between col5 & col6 of file2?

Both files have the same number of rows and the identifiers in col for both files match.

Is there a solution for this?
 
Old 05-28-2011, 11:33 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Have a look at awk as it is able to grab a column and place it anywhere you like.
 
Old 05-28-2011, 12:26 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Is this something you need to do repeatedly, using a program or script, or just a once-or-twice thing that you could do with a text editor? If the former, then you probably want to look at a scripting language such as AWK or Perl, or possibly even Bash with a little help from sed. Give one of those a shot, and when you bump into problems, post your work here, and someone will be able to guide you.
If you just need to to a one-time copy & paste, then many plain-text editors can do column/block oriented copy & paste. I use nedit for my daily text editing, and it does a good job of manipulating columns of text.

--- rod.
 
Old 05-28-2011, 01:32 PM   #4
ozmj73
LQ Newbie
 
Registered: May 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks. I'll have a look to see what awk options are available and hopefully be able to construct the correct command.
 
  


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
[SOLVED] Insert a column of text to a text file docaia Linux - Newbie 5 06-02-2011 11:55 AM
script to insert no. of lines in a file to the start of the file LarsB Linux - Newbie 3 09-17-2009 09:22 PM
using sed to insert line into file and overwrite the current file jadeddog Programming 3 06-11-2009 08:14 PM
Read text file column by column RVF16 Programming 11 05-31-2009 08:16 AM
how to append columns form a column file in another file adam_blackice Programming 4 09-18-2007 12:33 AM


All times are GMT -5. The time now is 07:48 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