The UNIX and Linux Forums
>
Top Forums
>
UNIX for Dummies Questions & Answers
How to grep / zgrep to output ONLY the matching filename and line number?
.
User Name
Remember Me?
Password
google unix.com
Forums
Register
Forum Rules
Links
Albums
FAQ
Members List
Calendar
Search
Today's Posts
Mark Forums Read
Thread
:
How to grep / zgrep to output ONLY the matching filename and line number?
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
#
2
(
permalink
)
03-12-2008
keelba
Registered User
Join Date: Apr 2002
Location: Dallas, TX
Posts: 57
I would try something like this:
#!/usr/bin/ksh
for i in `ls *.txt`
do
grep "<STRING>" $i 1>/dev/null 2>&1
if [[ $? = 0 ]]
then
echo -n "${i}: "
grep -n "<STRING>" $i | awk -F: '{printf "%s",$1" "}'
fi
done
echo
keelba
View Public Profile
Find all posts by keelba
Find keelba's past nominations received
Find keelba's present nominations given