Computing.Net > Forums > Unix > Insert a line to many files

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Insert a line to many files

Reply to Message Icon

Original Message
Name: hismail
Date: September 6, 2005 at 08:27:26 Pacific
Subject: Insert a line to many files
OS: Sco Openser
CPU/Ram: 2 gig /2 gig
Comment:

Hi
I would like to insert a line to many files in a directory :
for example:
abc has to be inserted to files
harry.pf
barry.pf
tom.pf
The common denominator for these files are the "*.pf"
I need to insert "abc" any where inside these pf files.

Any help will be much apreciated
thanks


Report Offensive Message For Removal


Response Number 1
Name: Luke Chi
Date: September 6, 2005 at 08:57:14 Pacific
Reply:

for FILE in `ls *.pf`
do
echo abc >> $FILE
done


Luke Chi


Report Offensive Follow Up For Removal

Response Number 2
Name: hismail
Date: September 7, 2005 at 01:48:08 Pacific
Reply:

Hi luke Chi
Thanks its works great
Just 1 question, if i have to replace a field in the .pf files for example change
"128" to "256" ? what do I i use.
tried:
for FILE in `ls *.pf`
do
echo sed 's/128/256/g' >> $FILE
done

But it just outputs to screen

thanks for your help
Hamim


Report Offensive Follow Up For Removal

Response Number 3
Name: Luke Chi
Date: September 7, 2005 at 06:05:38 Pacific
Reply:

Use:

sed 's/128/256/g' `ls *.pf`


Luke Chi


Report Offensive Follow Up For Removal

Response Number 4
Name: hismail
Date: September 7, 2005 at 06:31:47 Pacific
Reply:

Hi Luke
I tried using `ls *.pf` instead of $FILE but it still also outputs to the screen.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home



Results for: Insert a line to many files

Writing specific lines to new file
    Summary: Hi, I have a file with 60 lines. I want to write from line 10-20 to one file, 21-40 to another new file, 41-60 to another new file. Can anybody please help me on this? ...
www.computing.net/answers/unix/writing-specific-lines-to-new-file/8034.html

Inserting header/foort to data file
    Summary: What is the easiest way of adding a header and a footer to a data file? I was considering sed but didn't get far. Any ideas? Thanks! ...
www.computing.net/answers/unix/inserting-headerfoort-to-data-file/6357.html

printing a line thru a loop
    Summary: hi, i am not doing integer aritmatic. i need to pick up a line from the file path.txt using sed command. with sed -n 1p path.txt will give me the first line from the file path.txt. so i am trying to ...
www.computing.net/answers/unix/printing-a-line-thru-a-loop/4673.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software