Aaron
Aaron

Reputation: 3325

Alter output of script

This code:

wget --output-document=- http://runescape.com/title.ws 2>/dev/null \
| grep PlayerCount \
| head -1l \
| sed 's/^[^>]*>//' \
| sed "s/currently.*$/$(date '+%r %b %d %Y')/" \
| cut -d">" -f 3,4 \
| sed 's/<\/span>//'

outputs something similar to:

112,915 people 10:44:54 PM Mar 18 2012

Can anyone help me make it so it will print out to look like:

3/18/2012 22:44:54 112,915 people

Thanks!

Upvotes: 0

Views: 84

Answers (2)

thb
thb

Reputation: 14454

Partial answer:

date '+%m/%d/%Y %H:%m:%S'

gives you the date format you want, except that March is made "03" rather than "3". If you really want March to be 3, then this works:

date '+%m/%d/%Y %H:%m:%S' | sed -e 's/^0//'

And, if you want to make March 9 into 3/9 rather than 03/09, well, you can exercise Sed in any of several ways, but this one is as straightforward as any:

date '+%m/%d/%Y %H:%m:%S' | sed -e 's/^0//' | sed -e 's/^\([[:digit:]]\+\/\)0/\1/'

Upvotes: 2

Blackle Mori
Blackle Mori

Reputation: 1181

You'll have to make your command this:

wget --output-document=- http://runescape.com/title.ws 2>/dev/null \
| grep PlayerCount \
| head -1l \
| sed 's/^[^>]*>//' \
| sed "s/currently.*$/$(date '+%m\/%d\/%Y %H:%m:%S')/" \
| cut -d">" -f 3,4 \
| sed 's/<\/span>//' \
| awk '{print $3, $4, $1, $2}'

Upvotes: 2

Related Questions