3

I am executing the below command to display the lines which matches the pattern.

find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507"

And output is

./files/N1.942_0000.txt:78787878|13|5|20150507221152 ./files/N1.942_0000.txt:78787878|13|5|20150507221156 ./files/N1.943_0002.txt:1221212|13|5|20150507222004 ./files/N1.810_0000.txt:8892716618|13|5|20150507215150 ./files/N1.442_0001.txt:8648648648|13|5|20150507221636 ./files/N1.442_0001.txt:8648648648|13|5|20150507221638 ./files/N1.442_0001.txt:7406079160|13|5|20150507221941

But i want output without file name like below.

78787878|13|5|20150507221152
78787878|13|5|20150507221156
1221212|13|5|20150507222004
8892716618|13|5|20150507215150
8648648648|13|5|20150507221636
8648648648|13|5|20150507221638
7406079160|13|5|20150507221941

2
  • 2
    Check if your system's version of grep supports the -h or --no-filename option Commented May 8, 2015 at 14:08
  • @steeldriver may as well post that as an answer.
    – terdon
    Commented May 8, 2015 at 14:25

3 Answers 3

2

grep command have -r option

it searchs text recursive over directory

example below:

grep -r "5|20150507" ./ | awk -F ':' {'print $2'}
1

Use grep with option "-h" .

 -h, --no-filename
             Suppress  the  prefixing  of file names on output.  This is    
  the default when there is only one file (or only standard input) to
          search.

find ./files/ -name "*.txt" -print0 | xargs -0 grep -h "5|20150507"

0
find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" | awk 'BEGIN{FS=":"} {print $2}'

You may have to play with the delimiter "FS=" as it could be a special character.

You must log in to answer this question.

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