cut -d with more than 1 delimiter?

I need to cut or otherwise get the 4th and 5th position output of

for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done

example output is:
h;13;1310318701;443;93

I only need ";443;93" from any given run of "for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done"

Thanks for your time.

What exactly does vnstat print?

You could just slap an awk at the end, but then the pipe chain would start getting pretty inefficiently long, might be better to rework this.

1 Like

Corona688:

vnStat a console-based network traffic monitor

I am using the output for a "bandwidth monitor" of a satellite subscriber piped into a Conky desktop 'decoration'.

They have hourly limits and they want the hourly usage displayed on the desktop.

Re: rework this- maybe
vnstat --dumpdb -h has a pretty graph but postionally I don't know if the 'hour' moves around the output shown http://susepaste.org/78935276

Hope that helps.
Thanks!

I too am also lurking on this post. :slight_smile:

Edit: I think I have an answer. I will advise...

I believe

for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done | cut -c 17- 

will do the trick.

---------- Post updated at 02:23 PM ---------- Previous update was at 01:58 PM ----------

Corona688:

Thanks for the timely response.

You rock!

---------- Post updated at 03:07 PM ---------- Previous update was at 02:23 PM ----------

The answer is:

#!/bin/bash
echo "Tx (MiB) for this hour is" $(for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done | cut -c 17- | cut -d\; -f1)
echo "Rx (MiB) for this hour is" $(for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done | cut -c 17- | cut -d\; -f2)

Thanks for listening.

root@wrtu54g:~# vnstat --dumpdb | awk -F';' '$2 == hr && $1 == "h" { print $4 FS $5 }' hr=`date +%H`
128570;4814
1 Like