What's new

Need some help with "sed" command

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

octopus

Part of the Furniture
Need some help with sed command.

I want to remove ":" from CPU out from this line: cpu="`cat /proc/dmu/temperature | sed 's/ø//'`"

Now I get this out put: CPU temperature : 77C

Thanks :)
 
How about:

cpu="`cat /proc/dmu/temperature | sed 's/ø// ; s/://'`"

or even the non-depreciated form

cpu="$(cat /proc/dmu/temperature | sed 's/ø// ; s/://')"
 
cpu="$(cat /proc/dmu/temperature | sed 's/\t: /XXXXX/ ; s/øC$/YYYYY/')"

Notice how the " : " is actually <tab><colon><space>
Code:
cat /proc/dmu/temperature | hd
00000000  43 50 55 20 74 65 6d 70  65 72 61 74 75 72 65 09  |CPU temperature.|
00000010  3a 20 38 35 f8 43 0a 0a                           |: 85.C..|
 
cpu="$(cat /proc/dmu/temperature | sed 's/\t: /XXXXX/ ; s/øC$/YYYYY/')"

Notice how the " : " is actually <tab><colon><space>
Code:
cat /proc/dmu/temperature | hd
00000000  43 50 55 20 74 65 6d 70  65 72 61 74 75 72 65 09  |CPU temperature.|
00000010  3a 20 38 35 f8 43 0a 0a                           |: 85.C..|
Thats give:
octopus@RT-AC68U:/tmp/home/root# cat /proc/dmu/temperature | sed 's/\t: /XXXXX/ ; s/øC$/grder/'
CPU temperatureXXXXX75

Prefered output is: CPU temperature 75 degrese

Thanks
 
Prefered output is: CPU temperature 75 degrese

Code:
cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/'
 
Code:
cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/'

When tested from xshell i get this out:
octopus@RT-AC68U:/tmp/home/root# cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/'
CPU temperature 75 degrese

But when in this case sending mail I get signs at then end: " øC "
CPU temperature 75 degreseøC

Thanks !
 
When tested from xshell i get this out:
octopus@RT-AC68U:/tmp/home/root# cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/'
CPU temperature 75 degrese

But when in this case sending mail I get signs at then end: " øC "
CPU temperature 75 degreseøC

Thanks !

Hmm strange... ;)

deja vu ?
 
A fairly horrible solution:
Code:
# cpu="$(printf "The temperature is %s degrees" $(cat /proc/dmu/temperature | sed 's/[^0-9]*//g'))"
# echo $cpu
The temperature is 82 degrees
 
When tested from xshell i get this out:
octopus@RT-AC68U:/tmp/home/root# cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/'
CPU temperature 75 degrese

But when in this case sending mail I get signs at then end: " øC "
CPU temperature 75 degreseøC

Not strictly 'sed' o_O
Code:
sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/ ; s/C$//' | tr -d '\xf8'
 
Not strictly 'sed' o_O
Code:
sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 degrese/ ; s/C$//' | tr -d '\xf8'
Thank you!
That working fine nothing more " øC " . I can read In mail: CPU temperature 77 degrees
Code:
2.4Ghz radio    50 Grader
5.0Ghz radio    52 Grader
CPU temperature 76 Grader
Thanks for all help. I have forgot about that deja vu.......... getting old :(
 
Code:
cat /proc/dmu/temperature | cut -d ":" -f 2
 
Code:
cat /proc/dmu/temperature | cut -d ":" -f 2
Thanks, that is also a solution and I can use my own text. ;)
But I get "77øC" as result when email from my scriptit.
 
Last edited:
Code:
cat /proc/dmu/temperature | cut -d ":" -f 2

Your code returns the spurious 2-char unwanted suffix that is invisible i.e. non-printable

Code:
cat /proc/dmu/temperature

CPU temperature : 74

i.e. how can the length of the expected 2 digits be 7 chars rather than 3 (includes leading space) or 5 if we include the two trailing LF chars?

Code:
cat /proc/dmu/temperature | cut -d ":" -f 2 | wc -c

7
 
Your code returns the spurious 2-char unwanted suffix that is invisible i.e. non-printable
It's only invisible because you are using an incompatible character set (the last "C" should always be visible anyway). So if you use ISO-8859-15 for example:
Code:
# cat /proc/dmu/temperature
CPU temperature : 84øC

Anyway, if @octopus wants to use completely different text then the solution in post #11 will work.;)
 
Thanks to all of you!

Both ways working just fine:
Code:
cpu="`cat /proc/dmu/temperature | sed -r 's/\t: // ; s/([0-9]{1,3})/ \1 Grader/ ; s/C$//' | tr -d '\xf8'`"

use completely different text
cpu="$(printf "CPU temperature %s Grader" $(cat /proc/dmu/temperature | sed 's/[^0-9]*//g'))"

Octopus

@ColinTaylor @RMerlin @Martineau
 
If this helps... snippet from another script I keep around...

Code:
#!/bin/bash
celsius=$(cat /sys/class/thermal/thermal_zone0/temp | sed 's/.\{3\}$/.&/')
echo "ARM Temp => ${celsius} °C"

which results in...

ARM Temp => 53.692 °C

tweak as needed - regular expressions are fun, until they're not :D
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top