Вторник, 19 мая 2015, 11:02 +02:00 от Richard Taubo <o...@bergersen.no>:
>Hi!
>
>
>> On 18 May 2015, at 18:27, Richard Taubo < o...@bergersen.no > wrote:
>>
>> Hi,
>>
>> and thanks to Shawn H Corey, Jing Yu.
>>
>> I see that I have not been specific enough.
>> (And sorry for the top posting).
>>
>> The full (bash) script with perl parts looks like this:
>> [$] top_return=$(top -n1 | head -5)
>> [$] io_return=$(printf "%s\n" "$top_return" | grep "^Cpu(s)")
>> [$] io_all=$(printf "%s" "$io_return" | awk '{ printf $9 }' | perl -pe
>> 's/\%st//')
>> [$] printf "%s\n" "$io_all"
>>
>> Returns => 0.0%st (would want it to be: 0.0 without the '%st'
>> part).
>>
>> This "kind of works":
>> [$] io_all=$(printf "%s" "$io_return" | awk '{ printf $9 }' | perl -pe
>> 's/\%//')
>> [$] printf "%s\n" "$io_all"
>> Returns => 0.0st (without the % sign)
>>
>> This too:
>> [$] io_all=$(printf "%s" "$io_return" | awk '{ printf $9 }' | perl -pe
>> 's/st//')
>> [$] printf "%s\n" "$io_all"
>> Returns => 0.0% (without the "st" characters)
>>
>> BUT when i search and replace for "%st" (as described above), I can’t
>> get it to work.
>>
>> Thanks for any feedback, and thanks again for the answers I have received.
>> :-)
>
>In the end, I ended up with two separate perl commands.
>One removing the "%" part of the text, the other the "st" part of the text:
Mistake. Here comes fix:
io_all=$(printf "%s\n" "$cp_return" | awk '{ printf $9 }' | perl -pe
's/.*/$&st/;'