Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



How can I make a change to all files in a directory?

Last updated: 02/08/2012
Here's short csh script to loop through each file and add a line to it:

#!/bin/csh
 
foreach i (`ls *.txt`)
     echo $i
     echo "new line" | cat >> $i
end

This lists all *.txt files, and adds the line "new line" to each file.  For more complicated edits, you should look at using sed or awk, but the foreach structure should still be helpful.
blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
What's an easy backup script for my mysql databases?



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.