3

I need to grep for a particular port number from a huge set of files.

I am using a command:

find . |xargs grep "9461"

But it does not finds all the occurrences for number 9461. Can anyone suggest a better unix/linux command to do so.

The kind of files it gets is : x.log, y.txt,z.htm, a.out etc files But it was not able to get abc.conf files

3
  • Post the kind of files that it matches, and those that should be matched but aren't. Commented Jun 2, 2014 at 12:15
  • The kind of files it gets is : x.log, y.txt,z.htm, a.out etc files But it was not able to grep in abc.conf files Commented Jun 2, 2014 at 12:19
  • What do you mean with "it was not able to grep n ab.conf files"? That there was some 9461 in abc.conf but wasn't shown? Use grep -H to be sure it prints the filename it is grepping. Commented Jun 2, 2014 at 12:32

1 Answer 1

1

You surely have some reason for using find in combination with grep, but just in case:

You can replace your command by:

grep -r "9461" .

and if you want even line numbers

grep -rn "9461" .

As JonathanLefflero commented, there is also the option -e that make grep match againt a regular expression, so, the ultimate command would be

grep -rne 9461

You should take a look on grep man page

A final note, you should check if what you want to grep is "9461" or 9461 without "".

Sign up to request clarification or add additional context in comments.

2 Comments

This can mean searching files multiple times as find lists the files and the parent directories, and the grep -r scans everything too. Using grep -r -e 9461 . might make sense.
@JonathanLeffler yes, you're right!! Editing right now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.