Grep and find combination


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep and find combination
# 1  
Old 09-23-2008
Grep and find combination

Hello All,

I'm trying the following:
Code:
find . -name "*" -exec grep -ln "IsAlpha" {} \;

It gives me file names only (having string "IsAlpha"), I want to get line numbers also, something like this: test 1: Line 52
test 1: Line 95 etc

Is it possible to obtain using grep & find only.
# 2  
Old 09-23-2008
grep -l turns off all the other output from grep. All you see is filename, and only if the string is found.
# 3  
Old 09-25-2008
Please suggest me if there is any alternative to achieve the above and also please advise if my way of using "find" is correct or there is anything I need to change?
# 4  
Old 09-25-2008
try something like this..
Quote:
find . -name "*" -exec awk '/IsAlpha/{print NR,FILENAME}' {} \;
# 5  
Old 10-06-2008
I tried the following:
Code:
find . -name "*" -exec awk '/IsAlpha/{print NR,FILENAME}' {} \;

But it takes very long time to finish, please note that I have to search in directory /data/Programs, but I think this command continues searching in whole /data directory, any suggestions to improve this search? Thanks in advance.
# 6  
Old 10-08-2008
find . -name "*" -exec grep -Hn "IsAlpha" {} \;
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using find for variable combination of perms

Hi, I'm trying to use find in kshell (AIX) to find all files with perms of write for other AND any execute bit set. e.g: r--r-x-w- would qualify and rw-rw--wx would qualify but ---rwxr-xr-x wouldn't qualify So far, I've been trying something like this: find . -type f -perm... (4 Replies)
Discussion started by: alanp36
4 Replies

2. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

3. Shell Programming and Scripting

Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix like below are the lines ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off = disabled the test.txt can content them in any order #cat test.xt ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off =... (5 Replies)
Discussion started by: SilvesterJ
5 Replies

4. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

5. UNIX for Dummies Questions & Answers

grep or find ?

I have a file called 'test.txt' that contains alphanumeric charecters. The file contains the word 'SBE' followed by other alphabets many times. For example, the file will contain: SBE334GH and also will have SBE77Y8I. When i do grep 'SBE*' test.txt - it outputs the entire file. Can you... (5 Replies)
Discussion started by: DallasT
5 Replies

6. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

7. Shell Programming and Scripting

Sed Awk Cut Grep Combination Help ?

I have been reading for a few hours trying to educate myself enough to accomplish this task, so please know I have performed some research. Unfortunately, I am not a *NIX scripting expert, or a coder. I come from a network background instead. SO, here is my desired outcome. I have some Cisco... (5 Replies)
Discussion started by: abbzer0
5 Replies

8. UNIX for Dummies Questions & Answers

problem with grep in combination with xargs

Dear all, I have tried the following 2 lines xargs -t -i -exec grep -i -w {} file_1 >>test < file_2 cat -s file_2| xargs -t -i -exec grep -i -w {} file_1 >> test They were meant to search for the contents of file_2 in file_1 and write the respective lines of file_1 into file "test" .... (15 Replies)
Discussion started by: Bruno
15 Replies

9. UNIX for Dummies Questions & Answers

Combination of find -xargs & wc -l

Dear all, I have to calculate sum of record count of files of the specified directory. First I tried the following way which prints one or more outputs. How can I sum of this output? find /home/work/tmp/1/O/ -type f -print0 | xargs -0 wc -l | grep total 1666288 total 1073908 total ... (4 Replies)
Discussion started by: mr_bold
4 Replies

10. Shell Programming and Scripting

'find' and 'tar' combination

I'm trying to tar the files I get from the 'find' command result. However I can't make it run successfuly? This is for our archiving process. Here is my script: find /mnt/LOGS -mtime -10 -name "TUXLOG.*" -exec tar -cvf /mnt/LOGS/combine.tar {} \; Im not sure why it is not working or it is... (2 Replies)
Discussion started by: kharen11
2 Replies
Login or Register to Ask a Question