LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   edit multiple lines of a text file into 1 line: (https://www.linuxquestions.org/questions/programming-9/edit-multiple-lines-of-a-text-file-into-1-line-717972/)

schneidz 04-09-2009 10:42 AM

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 ?

colucix 04-09-2009 10:45 AM

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

ghostdog74 04-09-2009 11:22 AM

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



All times are GMT -5. The time now is 06:41 PM.