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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Insert a line to many files

Reply to Message Icon

Name: hismail
Date: September 6, 2005 at 08:27:26 Pacific
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



Sponsored Link
Ads by Google

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


0

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


0

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


0

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: Insert a line to many files

Writing specific lines to new file www.computing.net/answers/unix/writing-specific-lines-to-new-file/8034.html

Inserting header/foort to data file www.computing.net/answers/unix/inserting-headerfoort-to-data-file/6357.html

printing a line thru a loop www.computing.net/answers/unix/printing-a-line-thru-a-loop/4673.html