command line text processing..

Discussion in 'Perl Misc' started by Jim Carter, Nov 10, 2003.

  1. Jim Carter

    Jim Carter Guest

    Hi all,

    I am on Windows:

    I have a customozed command "lsdesktops" (I mean when I run C:\>
    lsdesktops at cmd prompt) and it gives an output like below:
    --------------------------------------
    TEST-MACHINE1:Windows SP3 Memory
    TEST-MACHINE2:Windows SP1 Processor
    TEST-MACHINE3:Windows SP4 Configuration
    ......... ###and many more lines like the above three lines
    ---------------------------------------

    Now I need a commmand line perl code to strip off every thing that
    starts after colon (inlcuding colon).
    Ex: The output should be

    -------------------
    TEST-MACHINE1
    TEST-MACHINE2
    TEST-MACHINE3
    TEST-MACHINE4
    TEST-MACHINE5
    TEST-MACHINE6
    ......
    ......
    ---------------------


    I know I need to use -e option and reg expression, but is not giving
    me the exact result.

    Thanks,
    JCarter
    Jim Carter, Nov 10, 2003
    #1
    1. Advertising

  2. Jim Carter

    Kien Ha Guest

    Jim Carter wrote:
    > Hi all,
    >
    > I am on Windows:
    >
    > I have a customozed command "lsdesktops" (I mean when I run C:\>
    > lsdesktops at cmd prompt) and it gives an output like below:
    > --------------------------------------
    > TEST-MACHINE1:Windows SP3 Memory
    > TEST-MACHINE2:Windows SP1 Processor
    > TEST-MACHINE3:Windows SP4 Configuration
    > ........ ###and many more lines like the above three lines
    > ---------------------------------------
    >
    > Now I need a commmand line perl code to strip off every thing that
    > starts after colon (inlcuding colon).
    > Ex: The output should be
    >
    > -------------------
    > TEST-MACHINE1
    > TEST-MACHINE2
    > TEST-MACHINE3
    > TEST-MACHINE4
    > TEST-MACHINE5
    > TEST-MACHINE6
    > .....
    > .....
    > ---------------------
    >
    >
    > I know I need to use -e option and reg expression, but is not giving
    > me the exact result.
    >


    Show us your code so we know what it did right/wrong.

    lsdesktops | perl -F: -lane "print $F[0]"
    Kien Ha, Nov 10, 2003
    #2
    1. Advertising

  3. Jim Carter <> wrote:

    > I need a commmand line perl code to strip off every thing that
    > starts after colon



    perl -pe 's/:.*//s'


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hal styli
    Replies:
    6
    Views:
    389
  2. kaushikshome
    Replies:
    4
    Views:
    762
    kaushikshome
    Sep 10, 2006
  3. Gregor H.

    Processing command line arguments

    Gregor H., Apr 21, 2007, in forum: C Programming
    Replies:
    5
    Views:
    509
  4. News
    Replies:
    8
    Views:
    333
    James Kanze
    Sep 17, 2007
  5. Jack
    Replies:
    2
    Views:
    167
    Bullschmidt
    Mar 7, 2005
Loading...

Share This Page