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.. |
Quote:
|
Quote:
it shows numbers for the size of the processes... How can i have them sorted by the size? ps -l |sort +12 is right? |
in this command
Code:
find . -type f -exec grep -n "$1" {} /dev null \; what's the use of /dev/null?? |
Quote:
Code:
eg ps ax --sort=uid |
Quote:
|
thank you all for the answers..:) :)
|
Actually this is an exercise!
jimyg10 you, or anyone else who submits this code, will get nullified in the course so i suggest you drop it or try a different approach. |
refer to :
http://www.ceid.upatras.gr/courses/o...B5%CE%B9%CF%82 for more information on the exercise. The site is in Greek, but the examples should make it clear to you that this is truly an exercise. |
All times are GMT -5. The time now is 08:30 AM. |