simple perl script

J

Jerry Maguire

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
 
C

Chesucat

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"


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

--
(e-mail address removed)
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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top