Celeb Glow
news | March 21, 2026

Using an awk and sed command inside perl

I have a simple awk and sed command that I want to write into a perl script or alternatively use the perl equivalent? Any pointers would be appreciated

sed -e '1d;4d' -e 's/#/Time/' -e 's/TGID/PID/' -e 's/%guest/%CPU/' -e 's/RSS/%MEM/'
awk '{ print $1,$3,$7,$13,$NF }'

1 Answer

Without context, it's hard to give you exact answers, but Perl also has the s/// command, so that should be easy.

To skip given lines, you can add something like

next if $. == 1 || $. == 4;

To print only the given columns, you usually keep them in an array, and then just

print "@F[0,2,6,12] ", scalar @F;
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy