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.
loop through directory grep file at
Name: Eric_1 Date: May 9, 2005 at 03:20:15 Pacific OS: AIX CPU/Ram: N/A
Comment:
Hello all,
I have a directory containing a files. I need a function which loops through the directory and greps 2 attributes out of the files.
The file looks like:
Name='Eric' FMASK='^Eric_1'
The function should return Eric and Eric_1
process Eric and Eric_1 and grep the next name out of the next file in the directory.
Name: Eric_1 Date: May 9, 2005 at 07:26:09 Pacific
Reply:
This is what I have till now.
for i in `ls -a *.txt` do FILENAME=$i name=$(cat $FILENAME | grep Name) Name=${Name#name=} done
This loops through the directory, finds all the text files and gives back the Name. However, it gives it back with the quotes like: 'Eric' and I just need the Eric and the Eric_1
Thanks in advance
0
Response Number 2
Name: David Perry Date: May 10, 2005 at 04:40:12 Pacific
Reply:
#!/bin/sh set -xv for file in `find . -name "*.txt" -exec grep -l Name {} \; ` ; do name=`awk -F= '/Name/ { print $2 }' $file | sed -e "s/'//g"` fmask=`awk -F= '/FMASK/ { print $2 }' $file | sed -e "s/'//g"` echo "Name: $name Fmask: $fmask" done
Summary: Hi Tony, I'm always twitchy just running commands or scripts without building them up and testing them gradually, and without a final sanity check of seeing what it's going to do before I run it. Th...
Summary: Hello I am trying to write a script. This is the thing, I want to loop through all folders in a certain folder and send all files in these folders to a java program. The files are somewhere in the ne...
Summary: I have written a for loop to iterate through a file list in an array generated by a find command... I can only get it to make one pass but when I print the array it contains the two files that the fin...