Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing files to a script

Status
Not open for further replies.

SotonStu

Programmer
May 7, 2003
33
GB
What command line do i need to pass a program all files of a certain type one by one. for example, i need to write a shell script which passes all *.html documents into an awk script.

i think it may involve the find comand but i haven't managed to get anything worthwhile working.

Any help would be grateful
 
# all html file from the CURRENT directory DOWN to all the subdirs
find . -type f -name '*.html'

# all html file from the CURRENT directory
find . -type f -name '*.html' -prune

hi, SotonStu ;)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Are you my UNIX guardian angel? So can i in my script just have

find . -type f -name '*.html' | awk -f myawk?

btw vlad, with your multiple input awk script, it doesn't manage to print out the correct filename, because when it goes into the print loop outside of the END statement, the FILENAME has already moved onto the next FILENAME. i can't solve that problem either.
 
correct.

or (in ksh)

awk -f myawk $(find . -type f -name '*.html')

For the other issue, I'll post on the original thread.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
SotonStu ,I do not want to interfere in your discussion :) but if you really want to (I quote you) pass a program all files of a certain type one by one, you almost got it:

Code:
find . -type f -name '*.html' -exec  awk -f myawk \{} \;
or
Code:
find . -type f -name '*.html' | xargs -n1  awk -f myawk
or
Code:
find . -type f -name '*.html' | while read file; do awk -f myawk $file; done

Vlad code will pass all files together but it seems you deal with multiple input awk script in another thread.
 
Is it possible to have the find inside of a shell script, whereby the directory u wish to start your search in (and then progress through the whole hierarchy) is given as an argument to your shell script?
 
Yes, just do
find /start/searching/here -type f -name '*.html'
 
So if i have this in a shell script named script. what will the line look like so that instead of the /start/searching/here it takes in an argument? how do i use argv[] here?
 

myScript.sh /start/searching/here

#----------- myScript.sh
#!/bin/ksh

find &quot;${1}&quot; -type f -name '*.html'


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
How can i modify that lines so it not only finds all html files, but also all those ending *.htm?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top