hello
I need to write a command to list all files in my home direcotory that have the words "cable", "wire" and "wireless" in them. note that all three words must be in them. is it possible with grep?
best regards
homework? read the rules!
negative, not a homework! it's something I need to learn. was hoping for someone to give me some tips.
so... use grep...
grep cable /path/to/files/* | grep wire | grep wireless
Hi Nagraj
When u do a second and third grep, it will search for the patterns in the output of first grep i.e. in the filenames and not in files. Please let me know if i am wrong.
if they have a specific positions on the line
# grep "cable.*wire.*wireless" file
otherwise
awk '/cable/ && /wire/ && /wireless/' file
thanks but those words might be in different lines, awk and grep both look for words into one line at a time.
What about this approach?
#!/bin/ksh
count=0
found=0
for PAT in cable wire wireless ; do
((count=count+1))
if [[ $(grep -wc "$PAT" /tmp/111 ) -gt 0 ]] ; then
((found=found+1))
else
echo "$PAT not found"
exit
fi;
done
if [[ $found -eq $count ]]; then
echo "Found all patterns";
fi;
Thanks
Nagarajan G
then use "or"
egrep "cable|wire|wireless" file
awk '/cable/ || /wire/ || /wireless/' file
otherwise, show a sample of your file