I writing a shell script to parse some file using grep and use the result in subsequent commands.
The relevant part of the source code is
VERSION=`grep "^Stable tag:" readme.md | awk -F' ' '{print $NF}'`
echo $VERSION
echo "Readme file version is $VERSION is it correct"
The relevant line in the readme.md file is
Stable tag: 2.2.2
You would expect a output of
2.2.2
Readme file version is 2.2.2 is it correct
But I am getting the following as the output
2.2.2
is it correctrsion is 2.2.2
I am pretty sure there is no (non-printable or non-ascii) character at the end of line in my text file. I checked it by enabling the :set invlist command in vim.
Any idea why it is happening like this? Or any other ideas to debug this issue?
awk -F' ' '/^Stable tag:/{print $NF}' readme.mdawkthis way. Now that I have to includetralso (see the answer below), do you think I can still do it usingawkalone?man awkand I seesubthere. Probablly something likeawk -F' ' '/^Stable tag:/{sub("\r", "", $NF); print $NF}' readme.md, though I'd think about sed at that point already.