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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Information in Multiple Files

Status
Not open for further replies.

jestrada101

Technical User
Mar 28, 2003
332
Hello...
I have the following, which searches within a list a files for anything that starts with 2003 using the cut command.

I'd like for this to give me only the file names that return values that begin with 2003.

Thanks for any recommendations...

for i in BT*
do
echo "${i}"
cut -b76-89 "${i}" | grep ^2003
done
 
I figured this out.. and is working for what I need it to do...

Thanks!
JE

for i in BT*
do
cut -b76-89 "${i}" | grep ^2003
result=$?
if [[ ${result} == 0 ]]
then
echo "${i}" >> 2003files
fi

done
 
Is there a way to only have "cut" return a single value... once it finds the first 2003, i'd like for it to stop and then check the next file..

thanks!
JE
 
Try something like this :
[tt]
for i BT*
do
grep -l -E '.{75}2003'
done
[/tt]

Jean Pierre.
 
Oops, alittle error , must be read :
[tt]
for i BT*
do
grep -l -E '^.{75}2003'
done
[/tt]


Jean Pierre.
 
i get
bash-2.05$ grep -E
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
bash-2.05$

when trying to use "-E"

 
Try something like this:
for i in BT*
do awk 'substr($0,76,79)==2003{print FILENAME;exit}' $i
done > 2003files

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top