LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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 08-11-2012, 10:58 PM   #1
holyearth
LQ Newbie
 
Registered: Nov 2008
Posts: 5

Rep: Reputation: 0
Combine lines from file


Hello,

Input file looks like this:
apples
bananas
oranges and rice
pears
cherries
mango

I want output to look like this:
apples bananas
oranges and rice pears
cherries mango

It should combine line 1 with line 2 and line 3 with line 4 like that....

Right now, only way I can think is to use head -n 2 but I want output file to be created with all of input processed....

Thanks for all the help in advance!!!
 
Old 08-12-2012, 04:00 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Try this:
Code:
sed 'N;s/\n/ /' infile
The above appends the next line to the buffer, removes the \n and prints the buffer content.
 
Old 08-12-2012, 04:10 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Awk
Code:
awk 'ORS=NR%2?" ":"\n"' file
 
  


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
Inline perl - combine two lines, need space in between tcxnieman Programming 1 07-03-2012 10:51 AM
[SOLVED] Perl: how to replace blank lines in a file with given lines from another karamaz0v Programming 8 04-19-2012 07:48 AM
how to combine same lines to one in a file eagal Linux - Newbie 22 11-10-2011 09:20 PM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 07:18 PM
How would you combine files excluding the lines that are different? darcman Linux - Software 10 01-19-2009 08:23 PM


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