Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Command line Syntax

    Hi,

    I want to do a simple search replace on a unix command prompt. What i require is a syntax to do is?
    echo "I am Manish"|<perl command>
    output I am Jeff.

    Please help.

    Regards
    Manish U
    ------------------------------
    The information contained in this message is confidential and proprietary to KnowledgeWorks Global Limited, Mumbai, India. It is intended only for the use of the individual or entity to whom it is addressed. If you are not the intended recipient, or the authorized agent thereof, you are hereby notified that any disclosure, use, distribution, dissemination or copying in any form of any information contained in this message is strictly prohibited. If you have received this message by mistake or error, please notify us immediately by return email to the sender or by fax on number +91-22-28291673 and delete all copies of the original message.

    Phone : 91-22-56971177 Ext 323

    Manish Uskaikar Guest

  2. Similar Questions and Discussions

    1. Syntax error - line too long
      I'm trying to send a newsletter to a bunch of people using cfmail. Some of them receive it and some don't. The ones that do not recieve it get an...
    2. ASP Command Object Syntax Errors
      I'm having difficulty using a straight-forward ASP/VBScript Command Object generated by DMX04. The code is supposed to insert into a SQL Server 2000...
    3. Grant Command Syntax
      I've got a MySQL database which contains users and their passwords. I have a PHP script that allows me to add new users and passwords to the...
    4. RUN/execute a Command-Line command from an ASP page
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    5. RUN/execute a Command-Line command from an ASP page.
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
  3. #2

    Default Re: Command line Syntax

    Manish Uskaikar wrote:
    > Hi,
    >
    > I want to do a simple search replace on a unix command prompt. What i require is a syntax to do is?
    > echo "I am Manish"|<perl command>
    > output I am Jeff.
    >
    > Please help.
    >
    > Regards
    > Manish U
    > ------------------------------
    > The information contained in this message is confidential and proprietary to KnowledgeWorks Global Limited, Mumbai, India. It is intended only for the use of the individual or entity to whom it is addressed. If you are not the intended recipient, or the authorized agent thereof, you are hereby notified that any disclosure, use, distribution, dissemination or copying in any form of any information contained in this message is strictly prohibited. If you have received this message by mistake or error, please notify us immediately by return email to the sender or by fax on number +91-22-28291673 and delete all copies of the original message.
    >
    > Phone : 91-22-56971177 Ext 323
    >

    There must be a better way but what comes to my mind is

    echo "I am Manish" | perl -e 'while(<>){ s/Manish/Jeff/g ; print "$_"}'



    BTW why would you want to do it in perl
    A much faster alternative will be
    echo "I am Manish" | sed 's;Manish;Jeff'


    Bye
    Ram




    Ramprasad A Padmanabhan Guest

  4. #3

    Default Re: Command line Syntax

    On Dec 1, 2003, at 8:06 AM, Ramprasad A Padmanabhan wrote:
    > There must be a better way but what comes to my mind is
    >
    > echo "I am Manish" | perl -e 'while(<>){ s/Manish/Jeff/g ; print "$_"}'
    echo "I am Manish" | perl -pe 's/Manish/Jeff/g'

    James

    James Edward Gray II Guest

  5. #4

    Default Re: Command line Syntax


    On Dec 1, 2003, at 3:41 AM, Manish Uskaikar wrote:
    > I want to do a simple search replace on a unix command prompt.
    > What i require is a syntax to do is?
    > echo "I am Manish"|<perl command>
    > output I am Jeff.
    jeff,

    I am drieux.
    What I would recommend is something old school,
    in which you go with something like code:


    #!/usr/bin/perl -w
    use strict;
    my ($find, $replace) = @ARGV;

    while(<STDIN>)
    {
    $_ =~ s/$find/$replace/;
    print $_;
    }

    then you can do:

    [jeeves: 22:] echo "I am Manish" | ./simple_filter Manish Boyish
    I am Boyish
    [jeeves: 23:]

    if you then put your script in one of the directories
    which are in you PATH, as I do with my $HOME/bin,
    then it will be findable.

    As you want to 'grow it out' to handle the
    error cases such as not having enough arguments,
    and more and more complex RegEx, then you can
    style it as you like.

    HTH.

    ciao
    drieux

    ---

    Drieux Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139