Issue
Hi I have a script to read 4.29.0 and convert to 4-29-0
The raw file I am reading is this:
$ cat package.xml | grep version
<?xml version="1.0"?>
<version>4.29.0</version>
The command I have to read is this:
VERSION=$(grep "version" package.xml | awk -F '>|<' '{print $3}' | sed 's/\./-/g')
If I print it
echo "testing.. $VERSION"
This will print as follows
testing..
4-29-0
Why is there a new line character and how do I remoev this ? I want to see the string as
testing.. 4-29-0
Solution
Your initial grep is not sufficiently focused. You need to change
VERSION=$(grep "version" package.xml
to
VERSION=$(grep "<version>" package.xml
to ensure only the line that has the relevant content will be processed by the awk command.
Answered By - Eric Marceau Answer Checked By - Robin (WPSolving Admin)