need awk substitute

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi All,

How would I do this bash script in perl?

A="$( echo "" | awk -F "/" '{print $1}' )"
B="$( echo "" | awk -F "/" '{print $2}' )"

$ echo "A=$A    B=$B"
A=    B=24

Many thanks,

Re: need awk substitute

Quoted text here. Click to load it


[rw@doppelsaurus]~#echo | perl -pe 's/.*\///'
[rw@doppelsaurus]~#echo | perl -pe 's/\/.*//'

Assuming that $addr is '',

($ip, $mask) = split(/\//, $addr);

($ip, $mask) = $addr =~ /(.*)\/(.*)/;

($ip, $mask) = (substr($addr, 0, -3), substr($addr, -2));

There are many other ways.

Re: need awk substitute

On 07/11/2015 06:57 AM, Rainer Weikusat wrote:
Quoted text here. Click to load it

I love it.  Thank you!

Site Timeline