2

How can I plot the output of this command line with GNUPlot? What should the diagram script look like?

I want a histogram.

wget -O - -o /dev/null http://www.stackoverflow.com/ |
cat | cat | sed "s/</\n</g" |
grep '<\/\{0,1\}[a-zA-Z][a-zA-Z\:\._\-]\{0,\}' |
cut -f 2 -d"<" | cut -f 1 -d">" | cut -f 1 -d" " |
sed "s/\//\\n/g" |
sort | uniq -c |
tail -n +2 |
cut -c5-
  • 1
    Since the first invocation of sed(1) seems wrong, and you didn't mention what kind of data you want to plot, it is difficult to answer your question. :) – cinsk Dec 20 '11 at 0:15
  • @cinsk how is that sed wrong? It inserts a newline before each <. Correctly. – Kevin Dec 20 '11 at 0:37
  • I don't remember how to work gnuplot, I just use the help facility every time I want it. – dmckee Dec 20 '11 at 1:00
5

This should help you out. Write data to file (changed cut -c5- to cut -c4- because it was deleting the first digit):

wget -O - -o /dev/null http://www.stackoverflow.com/ | cat | sed "s/</\n</g" | grep '<\/\{0,1\}[a-zA-Z][a-zA-Z\:\._\-]\{0,\}' | cut -f 2 -d"<" | cut -f 1 -d">" | cut -f 1 -d" " | sed "s/\//\\n/g" | sort | uniq -c | tail -n +2 | cut -c4- > mydata.txt

Create myplot.dem (some custom initialization added here, change it as you like it):

set style data histogram
set style fill solid border -1
set log y
set boxwidth 0.9
set term png
set tics out nomirror
set xtics rotate by -45
set output "histogram.png"
plot "mydata.txt" using 1:xticlabels(2)

and finally:

gnuplot myplot.dem

creates your plot "histogram.png" in current directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.