LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-01-2015, 08:49 AM   #1
elija
Member
 
Registered: Jul 2008
Location: The garden of England. Technically, the compost heap.
Distribution: openSUSE Tumbleweed
Posts: 60

Rep: Reputation: 21
Merging the data in two files


I have two files

filea
Code:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.
Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.
Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Donec ut libero sed arcu vehicula ultricies a non tortor.
fileb
Code:
abcde
12we
dfgtert
aq
I am looking to add the data in fileb to the end of the corresponding line in filea spearated by || so it should look like:
Code:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.||abcde
Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.||12we
Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.||dfgtert
Donec ut libero sed arcu vehicula ultricies a non tortor.||aq
I could do this in python or perl easily enough but is there a clever bash one liner that would achieve the same thing?

Last edited by elija; 04-01-2015 at 09:06 AM.
 
Old 04-01-2015, 08:51 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,116

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
man paste ?

maybe use some unique symbol for the output delimiter in paste then pipe to sed to substitute the single character delimiter into the multi-byte delimiter you want:
Code:
[schneidz@hyper ~]$ head tmp1 tmp2
==> tmp1 <==
hello
world

==> tmp2 <==
chun-li
akuma
[schneidz@hyper ~]$ paste -d \* tmp1 tmp2 | sed s/*/\|\|/
hello||chun-li
world||akuma

Last edited by schneidz; 04-01-2015 at 08:59 AM.
 
1 members found this post helpful.
Old 04-01-2015, 09:05 AM   #3
elija
Member
 
Registered: Jul 2008
Location: The garden of England. Technically, the compost heap.
Distribution: openSUSE Tumbleweed
Posts: 60

Original Poster
Rep: Reputation: 21
Exactly what I was looking for. Thanks.
 
  


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
Merging many files as one niharikaananth Linux - Newbie 5 08-15-2011 01:07 PM
Merging Data Files toshibalaptoplinux Linux - Newbie 6 12-14-2008 11:32 PM
Merging Two Files using C++ ckoniecny Programming 5 09-26-2006 09:00 AM
merging log files help please digitalgravy Linux - Newbie 3 12-10-2003 02:26 PM
WP for cmd-line data merging & printing? MikHud Linux - Software 0 11-06-2002 02:36 AM


All times are GMT -5. The time now is 10:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration