I using shell script to replace a number in the text file . Content of file is:
cat file
7.0.78 | 8.0 | 7.0.47
And I am using below command . This is working from command prompt but not from script.
Actual=8.0.44.0
sed -i -e "s/8.0/$Actual/g" file
I am getting output as | 7.0.478.0.44.0
from debug mode , I noticed that my variable become as:
+ Actual=$'8.0.44.0\r'
+ echo $'8.0.44.0\r'
Please advise, how to fix this issue. Thanks
\r
characters are a tell-tale clue: your script has DOS/Windows line-endings. You need to remove them withdos2unix
or similar tool. In the future create scripts using a Unix-aware editor. – John1024 Oct 05 '17 at 06:51sed
script. Although the root cause is the same, I vote to reopen, so the comment can be turned into an answer. – Philippos Oct 05 '17 at 08:13sed
command. Given that particular expression,sed
isn't behaving strangely at all. – Anthony Geoghegan Oct 05 '17 at 09:37sed -i
command if you runcat -v file
. When printing to screen, the carriage return moves the cursor to the start of the line so that the first 9 characters are over-wriiten. – Anthony Geoghegan Oct 05 '17 at 09:44