Computing.Net > Forums > Unix > loop through directory grep file at

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

Reply to Message Icon

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.

Can anyone help me out?

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: loop through directory grep file at

removing duplicated files www.computing.net/answers/unix/removing-duplicated-files/6462.html

Cygwin, loop through folders www.computing.net/answers/unix/cygwin-loop-through-folders/7447.html

Why won't this loop??? www.computing.net/answers/unix/why-wont-this-loop/5557.html