1

Possible Duplicate:
How to Combine find and grep for a complex search? ( GNU/linux, find, grep )

I have a file containing a text:

PADLST20120907:D:05B:UN:IBTA+TK4 17 JFL01+01'BGM+250+C'RFF+TN:TK4

I want to find this file in Linux, using these two strings: "JFL" and "20120907". As you see above, the file contains both "JFL" and "20120907". What should I write in command line? Stirngs may or may not be in the same line.

I want to see file names with full path in the output. I don't want to see error messages or permission denied warnings. I want to search recursively in the directory I am standing in or I would like to specifiy a path.

regards

0

1 Answer 1

3

A simple bash loop will do what you need:

$ grep -rl JFL . | while read n; do grep -l 20120907 $n; done

If your file names contain spaces, do:

$ grep -rl JFL . | while read n; do grep -l 20120907 "$n"; done

To suppress error messages, redirect standard error :

$ grep -rl JFL . 2>/de/null | while read n; do grep -l 20120907 "$n"; done

Not the answer you're looking for? Browse other questions tagged .