I'm using shell script and I want to add a space at the end of the line if the last characters are: ,.-
I've tried sed 's/,.-\r\n/,.- \r\n/g' part2.out > part3.out
but it didn't work, what am I missing?
Use $
to match the end of line, and escape the .
:
sed 's/,\.-$/,.- /'
You should probably use &
as well, and you might prefer to only do the replacement if the line matches:
sed '/,\.-$/s//& /'
Since your lines appear to have DOS line endings, you might want to take care of them with dos2unix
or some other utility more suited to that. One simple (but not robust) solution is to just delete the \r
characters, since you almost certainly do not actually want them in the data:
tr -d \\r < part2.out | sed 's/,\.-$/& /' > part3.out
is probably good enough. If Jaypal is correct and you are trying to match any line that ends in any of the characters ,
, .
, or -
instead of ending with the string ,.-
, then you want:
sed 's/[,.-]$/& /'