You are not logged in.
I want grep to output only what it matched, but according the man page, it will put each matching part on a separate line, which does not work for me. I am matching two numbers, but they don't get output together, but each on a separate line. Any idea how to fix this?
Here is my code:
[x@arch ~]$ sudo hddtemp /dev/sda|cut -f4 -d" "|grep [[:digit:]+] -o
4
6
Last edited by awayand (2012-03-31 05:08:06)
Offline
man tr
This might complain about trying to replace something with nothing. If that happens, just replace \n with another something, and then sed can dispose of the new something.
Offline
Or use awk and printf:
awk '{printf "%s ", $3}' <(sudo hddtemp /dev/sda /dev/sdb)
Offline
genius. thanks, dev/zero!
sudo hddtemp /dev/sda |cut -f4 -d" "|tr -cd [:digit:]
Offline
genius. thanks, dev/zero!
sudo hddtemp /dev/sda |cut -f4 -d" "|tr -cd [:digit:]
Haha, the actual solution you found is more elegant than the one I had in mind!
sudo hddtemp /dev/sda | cut -f4 -d" " | grep [[:digit:]+] -o | tr '\n' ' ' | sed 's| ||g'
Offline