I have a cshell script that is something like this:
`netstat -ap | & grep tcp | grep myprocess | awk '{print $4}' | awk 'BEGIN { FS = :"}{print $2}'`
This is how it works
1.
$ netstat -ap | & grep tcp | grep myprocess
tcp 0 0 *:1234 *:* LISTEN 8888/myprocess
2.
$ netstat -ap | & grep tcp | grep myprocess | awk '{print $4}'
*:1234
3.
$ netstat -ap | & grep tcp | grep myprocess | awk '{print $4}' | awk 'BEGIN { FS = ":"}{print $2}'`
1234
I need to make this as portable as possible using Perl. I think portability can't be guaranteed without the behaviour of netstat
and grep
, so I will try to make sure that they are supported on the target systems.
I am looking for
- Any general considerations to keep in mind to make the Perl script portable?
- How can I replicate the
awk
behaviour in Perl? - Can I also replicate the behavior of
grep
in Perl? Is that advisable (I'll do it only if Perl's grep has any advantages)?
[I am targeting all prevalent Windows and Linux versions here]