Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    2

    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
    Code:
    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.

    Thanks

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Hey,

    Your code works fine for me.
    Code:
    # 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
    Just Joined!
    Join Date
    Nov 2011
    Posts
    2
    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
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Maybe there are carriage returns in there, thanks to Windows?

    You can see them with:

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

    Code:
    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
  •