Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

would like to write a bash program which if I type in the following:

-bash-4.1$ ./sample.sh path regex keyword

that will result something like that:

path/sample.txt:12

path/sample.txt:34

path/dir/sample1.txt:56

path/dir/sample2.txt:78

I have absolutely no idea how can I achieve this without using find or grep -r (but I can use grep/ sed/ awk) in bash... Please help...

Thank you very much!!

share|improve this question
3  
add comment

closed as too localized by Gilles, Michael Mrozek Jan 9 '13 at 3:30

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

shopt -s globstar
awk '/search-string/ { print FILENAME ":" NR }' **/*

globstar enables recursive globbing. NR holds the current line number.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.