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

Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
user1731553
  • 1,887
  • 5
  • 22
  • 33
  • Post the kind of files that it matches, and those that should be matched but aren't. – DBedrenko Jun 02 '14 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 – user1731553 Jun 02 '14 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. – fedorqui Jun 02 '14 at 12:32

1 Answers1

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 "".

Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60