Use the -e
option. See it in man sed
So in your case you can do:
cat tmp.txt | grep '<td>[0-9]*.[0-9]' \ | sed -e 's/[\t ]//g' \ -e "s/<td>//g" \ -e "s/kB\/s\((.*)\)//g" \ -e "s/<\/td>//g" > traffic.txt
You can also write it in another way:
grep "<td>.*</td>" tmp.txt | sed 's/<td>\([0-9.]\+\).*/\1/g'
\+
matches one or more instances, but does not work on sed versions other than GNU. (For example, Mac has BSD)
With the @tripleee comment below, this is the most advanced version I could get, which will also work with non-GNU sed
versions:
sed -n 's/<td>\([0-9]*.[0-9]*\).*/\1/p' tmp.txt
As a side note, you can also just pass the output through every sed, rather than save every output, which I see how people usually do for special tasks:
cat tmp.txt | grep '<td>[0-9]*.[0-9]' \ | sed -e 's/[\t ]//g' \ | sed "s/<td>//g" \ | sed "s/kB\/s\((.*)\)//g" \ | sed "s/<\/td>//g" > traffic.txt
The -e
option is more efficient, but the connection option is more convenient, I think.
source share