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. :-)
Best regards,
Richard Taubo
> On 18 May 2015, at 17:52, Shawn H Corey <[email protected]> wrote:
>
> On Mon, 18 May 2015 17:32:03 +0200
> Richard Taubo <[email protected]> wrote:
>
>> Hi!
>>
>> Trying to remove the literal text "%st" from the command line return
>> value: 0.0%st as in:
>> [$] printf "0.0%st" | perl -pe 's/\%st//'
>>
>> I have also tried:
>>
>> [$] printf "0.0%st" | perl -pe 's/\Q%st\E//'
>>
>> Neither works.
>>
>> Would be happy if someone had any input here! :-)
>>
>> Thanks!
>>
>> Richard Taubo
>
> I'm not sure what you're trying to do but if you want a percent sign in
> a printf specification, use two of them.
>
> printf "Sale: %d%% off", $percentage_off;
>
> See `perldoc -f sprintf`
> <http://perldoc.perl.org/functions/sprintf.html>
And:
> On 18 May 2015, at 17:49, Jing Yu <[email protected]> wrote:
>
> Hi Richard,
>
> When you
> printf "0.0%st”
> in the command line, it prints
> 0.0t
> And that is the string piped to perl. This is perhaps why you didn’t succeed.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/