LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 09-28-2011, 12:17 PM   #1
jawsnnn
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Rep: Reputation: Disabled
How to join set of two lines together?


Example:

Let us say I have two sets of lines

1 2 3 4
5 6 7 8
9 10 11 12

and

A B C D
E F G H
I J K L

And I want the output to be :

1 2 3 4 A B C D
5 6 7 8 E F G H
9 10 11 12 I J K L

Is this possible using some simple command in Linux? Or will I need to use awk (or maybe sed) in a loop to accomplish this?

Problem with using the above two commands (sed/awk) in a loop is that I fear that might not be optimal as far as performance of code is concerned as the files I am working with are huge (millions of records each).
 
Old 09-28-2011, 12:21 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

A combination of diff and sed should work:
Code:
diff -ty file1 file2 | sed 's/[ |]*/ /g'
There are probably other ways as well.

Anyway, hope this helps.
 
Old 09-28-2011, 01:10 PM   #3
jawsnnn
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile

This seems like a simple and easy way of doing what I intend to do. Thanks a lot!!!!
 
Old 09-28-2011, 02:40 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
You're welcome

BTW: Can you put up the [SOLVED] tag.
first post -> Thread Tools -> Mark this thread as solved
 
Old 09-28-2011, 02:52 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Hi,

another alternative would be:
Code:
paste -d' ' file1 file2
 
1 members found this post helpful.
Old 09-29-2011, 01:25 PM   #6
jawsnnn
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks crts, that is exactly what I was looking for
 
Old 09-29-2011, 11:32 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Have a look at info coreutils. There are a lot of default commands available for doing simple tasks like this.
 
0 members found this post helpful.
  


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
join lines s_linux Programming 5 04-11-2011 10:00 AM
Join lines in text file vidyashankara Linux - General 10 12-21-2009 03:17 PM
join lines until a $ is found powah Programming 2 07-26-2007 03:19 AM
Join all lines using sed chipix Programming 3 04-03-2007 09:55 AM
join every three lines of a text file powah Programming 8 02-01-2007 11:40 PM

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

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