LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-11-2019, 08:13 AM   #1
rajdeepmukherjee
LQ Newbie
 
Registered: Oct 2019
Posts: 2

Rep: Reputation: Disabled
Merge two files and combine data


Dear friends, I need to merge two files, each file has 5 columns, I need to merge files based on first four columns. All fields do not have data and an empty field must be replaced with "Not Defined". Both the files have different numbers of rows.

Example:

file 1

a b c d e
a c d f
g f h j

File2

a b c d g
a c c b x

Output File

Name Value in file1 Value in file2
a b c d e g
a c d f Not Defined
g f h j Not Defined Not Defined
a c c c Not Defined x

Could somebody suggest a solution please. Many thanks in advance.
 
Old 10-11-2019, 08:29 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,319
Blog Entries: 3

Rep: Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725
Welcome.

We won't do the homework for you but can help you past the hard parts. The GNU Core Utils package will likely have what you need. Can you please say what you've tried so far and which hints have been provided by your instructor?
 
Old 10-11-2019, 08:42 AM   #3
rajdeepmukherjee
LQ Newbie
 
Registered: Oct 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Welcome.

We won't do the homework for you but can help you past the hard parts. The GNU Core Utils package will likely have what you need. Can you please say what you've tried so far and which hints have been provided by your instructor?
Thank you very much for replying. I already have a working bash script which is incredibly slow as I am operating on many pairs of large files. In my solution I just looped through all lines of first file, examined corresponding value in second file ( if exists ) and printed the record in output file. Then I looped through all lines of second file and performed same steps. It would be extremely helpful to get suggestions on doing it more efficiently. Thank you once again.
 
Old 10-11-2019, 08:44 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,319
Blog Entries: 3

Rep: Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725Reputation: 3725
Can you please show either your shell or AWK script so we can see where you are at in the process of finding a solution and propose improvements?
 
Old 10-11-2019, 09:20 AM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,374

Rep: Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754
Quote:
Both the files have different numbers of rows.
How should this be resolved?>
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge many files in to one big file. like 20 file merge in one big file Jmor Linux - Newbie 2 10-29-2008 09:41 PM
LXer: kgdb, To Merge Or Not To Merge LXer Syndicated Linux News 0 02-05-2008 06:10 PM
LXer: KHTML Vs Webkit: To Merge or Not To Merge LXer Syndicated Linux News 0 10-27-2007 06:41 AM
convert and merge a fat32 to ext3 and then merge w/ another ext3? nkoplm Linux - General 3 03-23-2006 10:37 PM
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 - General

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