LinuxQuestions.org
Visit the LQ Articles and Editorials section
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, 10:42 AM   #1
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,582

Rep: Reputation: 753Reputation: 753Reputation: 753Reputation: 753Reputation: 753Reputation: 753Reputation: 753
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 10:43 AM.
 
Old 04-09-2009, 10:45 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
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, 11:22 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 242Reputation: 242Reputation: 242
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 01:31 PM
print a text file with long lines and line number added powah Linux - General 2 05-26-2006 02:02 PM
command line edit -- global find/replace on text file w/o going into vi car182 Linux - Newbie 4 05-25-2006 05:42 PM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 02:38 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM


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