Monday, November 28, 2011

Shell Code to Recursively search a directory for files and process them one by one

for FILE in `find . -name $FILENAME`
## Process $FILE
echo "FILE: $FILE"
cat "$FILE" |
# Read Header but don't process it
read line
# Read records
while read line
echo $line

The above shell script code searches through current directory (and subdirectories) for all files with name RECORDS. It then reads the files one by one and processes them line by line.
Eg. If your record file is like follows
Then you could put following code to read off all names in while loop.
$NAME=`echo $line| cut -d"," -f1`
echo $NAME

No comments:

Post a Comment