Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl solution

by Anonymous Monk
on Jan 27, 2008 at 19:37 UTC ( [id://664552]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Perl solution
by shmem (Chancellor) on Jan 27, 2008 at 19:54 UTC
    The CoC* service responds: insert coin here.

    Seriously, what problems do you have, what did you try, did you read the PerlMonks FAQ and not stumble over How do I post a question effectively? Hard to believe.

    For a starter,

    netstat -e | perl -ple 's/\s\s+/\t/' > file.csv

    writes the output of netstat -e into a tab delimited csv file. You have to tweak the regular expression used in that snippet according to the spec.

    What spec? Ah, uhm, wait, er...

    *) Crank out Code

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      netstat -e | perl -ple 's/\s\s+/\t/' > file.csv

      Very likely an intended g modifier is missing from that s///. Of course, without a problem specification, who can say for sure that the g is needed? :)

      -Mike
      a tab delimited csv file

      I think you mean "a tsv file". A csv file is, by definition, comma delimited. A better version would probably be something like this:

      netstat -e | perl -ple 's/\s\s+/,/' > file.csv

      . . . and, of course, neither of our versions are exactly perfect/complete.

      print substr("Just another Perl hacker", 0, -2);
      - apotheon
      CopyWrite Chad Perrin

        You are certainly not wrong, but it could be argued that csv became a 'backronym' of Character Separated Values.

        How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
        Robot Tourist, by Ten Benson

      ** or Cockup Operations Corrector
Re: Perl solution
by citromatik (Curate) on Jan 28, 2008 at 16:28 UTC

    Alternatively, you can feed your script with the output of netstat -e opening a pipe:

    use strict; use warnings; open NETSTAT, "netstat -e |" or die $!; while (<NETSTAT>){ # process the line # Output to csv } close NETSTAT;
    citromatik
Re: Perl solution
by Anonymous Monk on Jan 27, 2008 at 19:38 UTC
    typo in netstat

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://664552]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found