Announcement

Collapse
No announcement yet.

Sed: replace alternate newlines

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Sed: replace alternate newlines

    I have managed to make grep output some numeric data, as so:

    Code:
    280.000
    5.549325
    290.000
    5.607368
    300.000
    5.664339
    To import this into a spreadsheet, I need to convert alternate newlines into some other character (space, tab, or comma are fine), to get something like:

    Code:
    280.000,5.549325
    290.000,5.607368
    300.000,5.664339
    How would I use sed (or any other standard Linux tool, but sed seems like what to use) to do this?
    I am running Ubuntu 8.10 (yes Gnome) with upgrades applied daily about 0900 UK time. Hardware is Dell Precision 420, 2x 800 MHz PIII, 512 MB RDRAM, nVidia GeForce 6800 128 MB AGP graphics, 18GB SCSI and 500GB IDE HDDs, DVD burner, Hauppage TV card.

    #2
    Re: Sed: replace alternate newlines

    Links:

    rmnl — remove new line characters with tr, awk, perl, sed or C/C++
    very-long -URL

    HANDY ONE-LINERS FOR AWK
    http://www.ee.ucl.ac.uk/~hamed/misc/awk1line.txt

    The GNU Awk User's Guide
    http://www.gnu.org/software/gawk/manual/gawk.html


    => HANDY ONE-LINERS FOR AWK tells:
    Code:
     # concatenate every 5 lines of input, using a comma separator
     # between fields
     awk 'ORS=%NR%5?",":"\n"' file
    If output.txt is
    280.000
    5.549325
    290.000
    5.607368
    300.000
    5.664339
    then
    Code:
    awk 'ORS=NR%2?",":"\n"' output.txt
    will print:
    280.000,5.549325
    290.000,5.607368
    300.000,5.664339
    Before you edit, BACKUP !

    Why there are dead links ?
    1. Thread: Please explain how to access old kubuntu forum posts
    2. Thread: Lost Information

    Comment

    Working...
    X