LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-09-2009, 11:42 AM   #1
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,213

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
edit multiple lines of a text file into 1 line:


hi, i got a file like this:
Code:
carrier-1 09-04-09_07:36:19
        Carrier Totals:  14245    5376298.39
carrier-2 09-04-09_10:09:23
        Carrier Totals:      2         95.00
carrier-3 09-04-09_10:09:48
        Carrier Totals:      1        306.00
and i want each group to appear on 1 line so i can grep/ sort / cut it easier like so:
Code:
carrier-1 09-04-09_07:36:19 Carrier Totals:  14245    5376298.39
carrier-2 09-04-09_10:09:23 Carrier Totals:      2         95.00
carrier-3 09-04-09_10:09:48 Carrier Totals:      1        306.00
does anyone have any ideas ?

Last edited by schneidz; 04-09-2009 at 11:43 AM.
 
Old 04-09-2009, 11:45 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Use the N command of sed to add the next line to the pattern space, then substitute the newline with a space and remove the spaces at the beginning of the second line:
Code:
sed '$!N;s/\n/ /;s/        //' file
 
1 members found this post helpful.
Old 04-09-2009, 12:22 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
awk
Code:
# awk 'ORS=(NR%2)?" ":"\n"' file
carrier-1 09-04-09_07:36:19         Carrier Totals:  14245    5376298.39
carrier-2 09-04-09_10:09:23         Carrier Totals:      2         95.00
carrier-3 09-04-09_10:09:48         Carrier Totals:      1        306.00
 
1 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
Combine multiple one column text file into one text file with multiple colum khairilthegreat Linux - Newbie 7 11-23-2007 02:31 PM
print a text file with long lines and line number added powah Linux - General 2 05-26-2006 03:02 PM
command line edit -- global find/replace on text file w/o going into vi car182 Linux - Newbie 4 05-25-2006 06:42 PM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 03:38 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 02:56 PM


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