Reputation: 141
I am having XML file say app_config.xml. This contains below line:
<conf>
<LOGFILENAME>seasonalitylog.$now.log</LOGFILENAME>
</conf>
I am reading in a script file say 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.
Upvotes: 1
Views: 40
Reputation: 1700
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)
Upvotes: 1
Reputation: 81012
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)
Upvotes: 2