Find the answer to your Linux question:
Results 1 to 4 of 4

Thread: Sed Basics..

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Sed Basics..

    Hi Guys,

    I have an application that requires a data file to load and I must use sed to modify the file accordingly.

    The problem is that each line in the config file is missing a comma at the end!

    So I've tried
    sed 's/$/,/' configLines
    But for some reason this adds the comma at the start of the file. Well... last time I checked, '$' meant end of the line! right??

    Let me know if there's another way to accomplish this or maybe my sed command is wrong.

    Any help would be appreciated.


  2. #2

    Your code works fine for me.
    # cat ./testfile.txt
    a b c d e
    1 2 3 4 5
    # sed -i.bak 's/$/,/' ./testfile.txt
    # cat ./testfile.txt
    a b c d e,
    1 2 3 4 5,

    ...can you post your configLines file if the problem is there?

  3. #3
    Okay thank you!!
    So I figure it must be my datafile! I think its worth noting that I copied the file over from win 7 -> Linux so maybe its not valid because of this?

    Interesting, I opened the file and the first record starts with '' whatever that is... I think the data must be corrupt.
    Last edited by EricTheRed; 11-22-2011 at 10:34 PM.

  4. $spacer_open
  5. #4
    Maybe there are carriage returns in there, thanks to Windows?

    You can see them with:

    cat -v file.txt
    If there, you will see ^M at the end of each line.
    You can remove them with:

    dos2unix file.txt

Posting Permissions

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