Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2007
    Posts
    25

    Unanswered: Replace new line with comma

    Hi Experts,

    The following is my contents of the file

    ABC

    EFG

    My output should be as follows

    ABC,EFG

    How can I acheive this with sed?

    Thanks in advance
    Regards,
    Poornima

  2. #2
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    Is this the entire input file?

  3. #3
    Join Date
    Mar 2007
    Posts
    25
    For an example I have just given two lines. But in reality my input file consists of 100's of lines.

    Is there way to acheive my need using SED or AWK?

  4. #4
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    If awk is acceptable:

    Code:
    awk 'NR==1{x=$0;next}NF{x=x","$0}END{print x}' filename
    Use nawk or /usr/xpg4/bin/awk on Solaris.

  5. #5
    Join Date
    Feb 2007
    Location
    Chennai, TN
    Posts
    68
    if sed,
    sed -e :a -e N -e 's/\n/,/' -e ta yourfile.txt >newfile.txt

    reference
    http://www.linuxquestions.org/questi...ng-sed-191121/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •