You are not logged in.
Pages: 1
Hi, i need help with formating output from text.
For example i have this output:
/dev/sda: WDC WD1600BEVT-22ZCT0: 37°C
And i need format this output to "37°C" only or "/dev/sda" only or "WDC WD1600BEVT-22ZCT0" only.
I know only how i can format output to "/dev/sda" :
cat text.txt | head -c 8
Thanks
Last edited by STANKAR (2011-01-02 17:16:53)
Offline
echo "/dev/sda: WDC WD1600BEVT-22ZCT0: 37°C" | cut -c34-38
37°C
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
echo "/dev/sda: WDC WD1600BEVT-22ZCT0: 37°C" | cut -c34-38 37°C
Thanks a lot, i didn't know that is so simple.
Offline
echo "/dev/sda: WDC WD1600BEVT-22ZCT0: 37°C" | cut -d':' -f3
might be less brittle
Offline
I found new problem. I didn't use this commands for x-lined output.
for example output of this: cat /proc/acpi/battery/BAT1/state
present: yes
capacity state: ok
charging state: charged
present rate: 298 mA
remaining capacity: 10364 mAh
present voltage: 12529 mV
If i need format output to "10364" or "charged" which command i can use ?
Offline
This is getting repetitive...
awk '/^charging state/{ print $NF }' /proc/acpi/battery/BAT1/state
sed -n '/^charging state/s/.*:\(.*\)/\1/p' /proc/acpi/battery/BAT1/state
while IFS=':' read label val; do
[[ $label == charging state ]] && { echo $val; exit; }
done < /proc/acpi/battery/BAT1/state
There's many ways to do these things. I advise you to learn a little on your own as it will make your life in linux much easier and more productive.
http://mywiki.wooledge.org/BashGuide
http://mywiki.wooledge.org/BashFAQ
http://wiki.bash-hackers.org/doku.php
Last edited by falconindy (2011-01-02 17:50:00)
Offline
Pages: 1