apratik
apratik

Reputation: 141

Not able to resolve Unix command read from XML

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.

Upvotes: 1

Views: 40

Answers (2)

zerodiff
zerodiff

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

Etan Reisner
Etan Reisner

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

Related Questions