0

I am trying to remove any black spaces from the end of lines. I am doing this and I am wondering why it is not working.

sed -i '' 's/\s*$/ endOfLine/g' myFile

I get this

MyLine
endOfLine
MyLine
endOfLine

I expect this

MyLine endOfLine
MyLine endOfLine
Chris
  • 985
  • 2
  • 7
  • 17
  • seems like DOS line endings. Check with `cat -vet myFile` . If you see `^M$` at the end of each line, then run `dos2unix myFile` and try your code again. (the trailing `g` is redundant when you are anchoring your search to the end of the line). Also, I don't think `sed` honors `\s` for white-space (unless maybe you can use a -P (for perl) option). Just use `s/[[:space:]][[:space]]*$/ endOfLIne/` . Good luck. – shellter Aug 25 '17 at 03:53
  • Thank you. "dos2unix myFile" was exactly what I needed. – Chris Aug 25 '17 at 16:22
  • I am having an issue though. My script is run every x mins in crontab. Running my script manually as root works fine, but the cron doesn't appear to be running the dos2unix command. Any ideas? – Chris Aug 25 '17 at 16:47
  • Please learn to use S.O. as a resource of existing Q/A. Searching for `[linux] script not working in cron` shows over 100 Q/A. Good luck. – shellter Aug 25 '17 at 16:58
  • Thanks but I just figured it out. I had to specify the dos2unix location in the command like this "/usr/local/bin/dos2unix myFile" – Chris Aug 25 '17 at 17:28

0 Answers0