Results 1 to 5 of 5
Hello,
I was wondering how to do the following script.
while not done
open file
write to end of file "hello"
save / close file
next file
I would like ...
- 12-18-2008 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 5
recursive file append
Hello,
I was wondering how to do the following script.
while not done
open file
write to end of file "hello"
save / close file
next file
I would like the script to edit every file *.* in a directory I choose, as well as every child directory.
./run_script /test/hello/test/script/
Thank you for your time
DL
- 12-18-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You can use "file" to print a list of all files matching certain criteria in and below the given starting directory and pass this list to "sed" (or "awk", or something similar) in order to append text to those files.
- 12-18-2008 #3
Where are you having difficulty with this? Or are you just looking for general tools to get you started?
The 'find' program will allow you to find files in a subtree starting at some directory that match a given pattern. 'cat' will print out a file, and 'echo' will allow you to print whatever string of text you want. You can redirect output of a command to append to a file by using '>>'. For example:
Does that help you at all?Code:cat file1 >> file2 # append the contents of file1 to file 2
DISTRO=Arch
Registered Linux User #388732
- 12-18-2008 #4Just Joined!
- Join Date
- Sep 2008
- Posts
- 5
I was having trouble in the sense that I have no clue where to start or how to do it.
"cat file1 >> file2 # append the contents of file1 to file 2"
is what I wanted but I want to do it recursivly through a directory and its sub directories.
cat "Hello" >> *.*
- 12-19-2008 #5
Code:[user@build]$ find temp1 -type f temp1/a/a temp1/b/b temp1/c/c temp1/d/d [user@build]$ [user@build]$ [user@build]$ [user@build]$ find temp1 -type f temp1/a/a temp1/b/b temp1/c/c temp1/d/d [user@build]$ find temp1 -type f|xargs cat [user@build]$ See carefully...no output for "cat" as no "data" was in the file. [user@build]$ for f in `find temp1 -type f`; do echo Hello >> $f; done [user@build]$ Now see the content at the end of each 4 files... [user@build]$ find temp1 -type f|xargs cat Hello Hello Hello Hello [user@build]$ [user@build]$ for f in `find temp1 -type f`; do echo "Hello SANGAL" >> $f; done [user@build]$ Now we added more data...at the end of each file...so cat will show 2 lines now i.e. 1st one is Hello and 2nd one is Hello SANGAL [user@build]$ find temp1 -type f|xargs cat Hello Hello SANGAL Hello Hello SANGAL Hello Hello SANGAL Hello Hello SANGAL [user@build]$ echo "gareebi" gareebi


Reply With Quote