1

I am having XML file say app_config.xml. This contains below line:

app_config.xml

<conf>
    <LOGFILENAME>seasonalitylog.$now.log</LOGFILENAME>
</conf>

I am reading in a script file say test.sh

test.sh

file_name=awk -F '</?LOGFILENAME>' $'{print $2}' app_config.xml

Tried using eval command : eval echo awk -F '</?LOGFILENAME>' '{print $2}' app_config.xml but it is not returning correct result. It is returning blank.

Please help me to understand where i am hoing wrong. Thanks in advance.

apratik
  • 141
  • 2
  • 11
  • Obvious thing that you are doing wrong is trying to parse XML with regular expressions. See this [answer](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#1732454) on why that's wrong. – Sorin Sep 24 '14 at 16:50

2 Answers2

2

You aren't running that awk command with that line.

You are assigning "awk" to the file variable and trying to run the -F command.

You need to wrap the awk command in $(....).

file_name=$(awk -F '</?LOGFILENAME>' $'{print $2}' app_config.xml)
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
1

For XML parsing, you may want to use xpath:

$ xpath -q -e "/conf/LOGFILENAME/text()" app_config.xml
seasonalitylog.$now.log

Or in a variable:

filename=$(xpath -q -e "/conf/LOGFILENAME/text()" app_config.xml)
zerodiff
  • 1,690
  • 1
  • 18
  • 23