LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2015, 05:45 PM   #1
bishop2001
Member
 
Registered: Apr 2015
Posts: 58

Rep: Reputation: Disabled
paste uneven columns


Hi
I have 2 files containing a column of uneven data in each.
file 1
12
765
998

File 2
Jerry
Alan

I'd like the output to look like:
12, Jerry
765, Alan
998

I tried paste but it's not lining up properly in 2 columns. Suggestions please
thanks
 
Old 12-01-2015, 06:51 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
That is what paste is designed to do - explain yourself.
 
Old 12-01-2015, 08:27 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
paste is the heart of a good solution.

With InFile1 ...
Code:
12
765
998
... and InFile2 ...
Code:
Jerry
Alan
... this paste ...
Code:
paste -d, $InFile1 $InFile2 >$OutFile
... produced this OutFile ...
Code:
12,Jerry
765,Alan
998,
Note that 998 has a trailing comma. If that bothers you, use this combination of sed and paste ...
Code:
paste -d"\0" $InFile1 <(sed 's/^/,/' $InFile2) >$OutFile
... to produce this OutFile ...
Code:
12,Jerry
765,Alan
998
Daniel B. Martin

Last edited by danielbmartin; 12-01-2015 at 09:42 PM. Reason: Correct t7pographical error
 
Old 12-01-2015, 10:25 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
I would simply delete the comma at the end of any line after the paste.
 
1 members found this post helpful.
  


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
merge columns from multiple files in a directory based on match of two columns prasanthi yanamala Linux - Newbie 2 11-12-2015 10:11 AM
[SOLVED] Converting a file with Rows and Columns to just Columns mphillips67 Linux - Newbie 14 03-05-2014 10:31 AM
[SOLVED] bash suggestions to convert horizontal columns to vertical columns Guyverix Programming 14 01-24-2013 11:03 AM
SQL statements howto -- 3 columns input but 2 columns output fhleung Programming 3 11-29-2012 10:45 AM
compare columns of uneven length bcrawl Linux - Newbie 7 01-20-2011 08:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:52 AM.

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