Reputation: 9581
I have the following command which exports out a date in milliseconds. I'm trying to have this stored as a variable so that I can use it later in my script:
epochlastUpdated= awk "/<pl:updated>/" feed.rss | head -n 1 | awk -F\< ' { print $2 } ' | awk -F\> ' { print $2 } '| date -j -f "%a, %d %b %Y %H:%M:%S %Z" "Fri, 13 Sep 2013 17:16:45 GMT" +%s000
I can't seem to get the script to have the output of that line stored in the epochlastUpdated variable?
Upvotes: 0
Views: 138
Reputation: 203512
You got your specific answer but this:
awk "/<pl:updated>/" feed.rss | head -n 1 | awk -F\< ' { print $2 } ' | awk -F\> ' { print $2 } '
can be done in 1 awk command:
awk -F\< '/<pl:updated>/{split($2,a,/>/); print a[2]; exit}' feed.rss
It can probably be even simpler than that, it depends what your input actually looks like.
Upvotes: 2
Reputation: 41456
Another short awk version:
awk -F"<|>" '/<pl:updated>/ {print $3;exit}' feed.rss
Upvotes: 1
Reputation: 289725
To store a command execution result, you need
var=$(command)
In this case,
epochlastUpdated=$(awk "/<pl:updated>/" feed.rss | head -n 1 | awk -F\< ' { print $2 } ' | awk -F\> ' { print $2 } '| date -j -f "%a, %d %b %Y %H:%M:%S %Z" "Fri, 13 Sep 2013 17:16:45 GMT" +%s000)
Upvotes: 2