Hello,
My OS: ubuntu 20
I do not understand why I am unable print expected output in this simple case:
Update: After couple attempts, I have found a way to get expected output from command line but it does not work in script.
Scratching my hair.
db
tv cine edition
tv cine action
nat geo wild
pt.xml
<channel id="TVCineAction.pt"><display-name>TVCine Action
<channel id="TVCineEdition.pt"><display-name>TVCine Edition
<channel id="NationalGeographicWildPortugal.pt"><display-name>National Geographic Wild
Expected:
tv*cine*edition TVCineEdition.pt TVCine Edition
tv*cine*action TVCineAction.pt TVCine Action
nat*geo*wild NationalGeographicWildPortugal.pt National Geographic Wild
What I am doing:
grep -i -m1 "wild" pt.xml
it returns empty.
I also tried dos2unix and chmod 644 it but no luck.
ls -la pt.xml:
-rw-r--r-- 1 root root 10787 Nov 5 00:31 pt.xml
when I run like below it is okay but not okay in command line:
grep -r -i -m1 "wild" pt.xml
<channel id="NationalGeographicWildPortugal.pt"><display-name>National Geographic Wild
Don't understand why it does not work just for the keyword "wild" but others.
Also tried pgrep, fgrep, egrep but no way.
get.sh
while read -r line
do
keyword=`echo "$line" | sed "s| |*|g"`
output=`grep -i -m1 -A0 "$keyword" pt.xml | sed "s|<channel id=\"||g" | sed "s|\"><display-name>|\t|g"`
echo -e "$keyword"'\t'"$output"
sed -e "/$keyword/Id" pt.xml > pt2.xml ; mv pt2.xml pt.xml #case insensitive delete and overwrite pt.xml
done<db > output
output:
tv*cine*edition TVCineEdition.pt TVCine Edition
tv*cine*action TVCineAction.pt TVCine Action
nat*geo*wild
As you can see C2 and C3 in third line are empty. Is this issue related to regexp or is there a special exception for the word wild in linux?
Thank you
Boris