simple perl script

Discussion in 'Perl Misc' started by Jerry Maguire, Aug 17, 2003.

  1. Hi,
    I would like to write a perl script to open and file and add a prefix to all
    the lines of that file.
    The file will be like:

    name1blah
    name2blah
    name3blah

    I have created the following script:
    #!/bin/sh
    cat test |
    while read name
    do
    printf 'new'$name>>newfile.txt;
    done

    Now the problem is it is adding all the lines in one line.
    The output is:
    newname1blahnewname2blahnewname3blah

    jerry
     
    Jerry Maguire, Aug 17, 2003
    #1
    1. Advertising

  2. Jerry Maguire

    Chesucat Guest

    On 18 Aug 2003, Sam Holden wrote:

    > Except of course that echo adds a newline by default. And echo \n will
    > output "n"... - since \n will be converted to n by most shells, if you
    > have a strange shell that doesnt do that then it'll output "\n"
    >
    > > In the future, you might want to post in comp.unix.shell!;-)

    >
    > A good idea.


    Yeah, I forgot about! But, anyway, it worked ksh! I figured he might
    have to tweak it some for his shell. I should had use '-n' option for the
    echo command, or I just should left the 'printf' statement in but I
    couldn't get it to work for me!:-( 'printf' has a lot more options than
    'echo', so I thought I would keep it simple with 'echo'. Thank you for
    pointing that out!

    chesucat

    --

    SDF Public Access UNIX System - http://sdf.lonestar.org
    Interpreter, n.:
    One who enables two persons of different languages to
    understand each other by repeating to each what it would have been to
    the interpreter's advantage for the other to have said.
    -- Ambrose Bierce, "The Devil's Dictionary"
     
    Chesucat, Aug 18, 2003
    #2
    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. Wet Basement
    Replies:
    1
    Views:
    2,543
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,830
  3. pj
    Replies:
    3
    Views:
    300
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    148
    Paul Lalli
    Jan 5, 2005
  5. Wladimir Borsov
    Replies:
    4
    Views:
    313
    Tintin
    May 11, 2006
Loading...

Share This Page