Bash script to search for specific pattern?
Hello guys..
I want your help.. I want to make a bash script (named *.sh), that will search all the files in all the directories under the current path for a specific pattern. The result would be filename:linenumber:line that has the specific pattern filename:linenumber:line that has the specific pattern filename:linenumber:line that has the specific pattern ... Anybody??? Thanks in advance... |
The man pages are your friend: man grep
Read the text on options '-H' '-n' and '-r' -- you don't need a script; just a single command. |
I work in minix3 and the command grep has only -e-l-n-s-v.., hasn't it??
|
Quote:
|
Quote:
Quote:
|
Anyone knows why???
|
Hi.
The "/dev/null" string (to force the display of the filename) appears to be out of order. This arrangement worked for me: Code:
find . -type f -exec grep -n "$pattern" {} /dev/null \; |
Thnx makyo.. But i have problem again.. It returns to me "Out of memory"...:confused: :confused:
it's ok if i replace "$pattern" with a specific pattern (example "echo").. I have another question.. How can i insert this command in a bash script named find.sh?? i want the user to enter: find.sh + pattern (for example find.sh echo) and the script to return the results.. Thnx in advance... |
Hi.
Quote:
Quote:
|
Quote:
Code:
find . -type f -print0 | xargs -0 grep -n "$pattern" |
I've done this:
Code:
ed Code:
chmod 755 test.sh |
Quote:
Code:
cat << EOF > "find.sh" |
Thank you all guys..:) :)
Now i have a few more general questions: a. How can i create a sorted list with the online users? b. How can i get all the files, whose names ends with c or h? c. How can i export all current processes in a .txt file and simultanusly on the screen? d. How can i get these processes sorted by their size on the screen? Thnx in advance whoever could help.. |
Quote:
Quote:
Code:
who | sort <options> Quote:
Code:
find /path -type f -name "*.c" -name "*.h" Quote:
Code:
ps | tee file Quote:
|
Quote:
thnx for alla the answers ghostdog74.. By the way, it's not homework.. |
All times are GMT -5. The time now is 11:06 PM. |