LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-07-2022, 03:37 PM   #1
sam_nyc
Member
 
Registered: Aug 2009
Posts: 73

Rep: Reputation: 1
how to merge two columns in different file and create third file


Hello,

Code:
File 1.txt
1 2 3 4 5

File 2.txt
6

I need to file 3.txt
1 2 3 4 5 6
First file has five columns and second file one column. I like to merge both together.

I tried cat, didn't work. any other idea, your help is greatly appreciated.
 
Old 04-07-2022, 04:35 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,762

Rep: Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763
man paste
 
Old 04-07-2022, 05:18 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,750

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by sam_nyc View Post
Hello,
Code:
File 1.txt
1 2 3 4 5

File 2.txt
6

I need to file 3.txt
1 2 3 4 5 6
First file has five columns and second file one column. I like to merge both together. I tried cat, didn't work. any other idea, your help is greatly appreciated.
Sounds familiar:
https://www.linuxquestions.org/quest...ne-4175708826/
https://www.linuxquestions.org/quest...ea-4175704050/
https://www.linuxquestions.org/quest...ng-4175692071/
https://www.linuxquestions.org/quest...rd-4175675529/

Been at least two years you've been working with scripting, and over TEN for Linux; why don't you show us exactly what you did try, and how you applied things you've been told before, to try to solve your problem, rather than just asking us to do it??
 
1 members found this post helpful.
Old 04-08-2022, 08:47 AM   #4
sam_nyc
Member
 
Registered: Aug 2009
Posts: 73

Original Poster
Rep: Reputation: 1
Thank you so much for your help. This is what I did.

paste file{1,2} | awk '{print $1,$2,$3,$6}' > file3
 
Old 04-08-2022, 09:47 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,750

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by sam_nyc View Post
Thank you so much for your help. This is what I did.
Code:
paste file{1,2} | awk '{print $1,$2,$3,$6}' > file3
Did you actually read the man page on paste, and what it does? Or think back to your previous TEN YEARS experience???
Code:
paste 1 2 | sed 's/\t/ /g' > 3
 
Old 04-08-2022, 02:23 PM   #6
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,762

Rep: Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763
Of course someone with only a year or two of experience MIGHT have tried
Code:
paste file{1,2}|expand|tr -s ' '
just to see what that might do.
 
  


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] Merging columns from different files and renaming columns lharrisl Linux - Newbie 7 05-23-2016 07:36 AM
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
awk command to merge columns from two separate files into single file? johnpaulodonnell Linux - Newbie 4 01-23-2007 10:10 AM
Is there a command to merge two files as two columns of one file? davee Linux - General 2 07-19-2005 10:52 AM

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

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