I need help using grep to extract a zoned date time from a file on a Linux system.
Source file is a XML with the data below:
<item start="20231010073000 +0100" stop="20231010100000 +0100">...</item>
And I need to extract the complete start date, but with grep I can't get it as a complete result. My code:
for startDate in $(grep -Eo 'start="[0-9]{14} [\+|\-][0-9]{4}"' "$filepath" ); do
echo "$startDate"
done
And I get it in two different results:
start="20231010073000
+0100"
Can I get it as bellow:
start="20231010073000 +0100"
I've tried with \s
, [[:space:]]
, and other examples, but with the same solution.
It seems an error in my code but I can't fix it!
I am thankful for any kind of help!!!
start=
as well?[\+|\-]
to a cleaner[+-]
- the escape backslashes are not necessary within[]
, and you don't want to match the vertical bar.item
, dates look like so: educba.com/xml-date