LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 10: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, 10:33 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Have a look at awk as it is able to grab a column and place it anywhere you like.
 
Old 05-28-2011, 11:26 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
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, 12: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



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

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

All times are GMT -5. The time now is 06:14 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
Open Source Consulting | Domain Registration