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:

io_all=$(printf "%s\n" "$cp_return" | awk '{ printf $9 }' | perl -pe 's/%//' | 
perl -pe 's/st//')
Returns =>  0.0 (without the "%st" characters)

That works fine, but looks a little clunky, are there perhaps other ways to 
unite the two
perl commands?

Thanks!

Richard Taubo
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to