0

Here I have some grep command which is not working correctly:

cat file1.txt:
apples
Date: Sun, 24 Feb 2013 8:14:06 -0800
peaches melons
cherry sky cloud
green purple
yellow

cat file2.txt:
apples
Date
peaches melons 0800
cherry sky cloud
green purple
black

Now broken command is:

egrep -lir "apples|melons|cherry" /home/test/* | xargs grep -l "Date" | xargs grep -l "0800"

See first argument: file must contain apples OR melons OR cherry Then, second argument: same file must contain "Date" and "0800" ON SAME LINE

So file1.txt should match but not file2.txt - right now both match

Thanks for the help - I think I need grep with regexp to match "Date:[any][any][any]0800" type command to catch "Date" and "0800" on same line....

1
  • Rather than giving us this very long but broken command, leaving us to guess what it does and how that differs from what you want, could you give us instead an example or two showing sample input and desired output? Feb 24, 2013 at 18:21

1 Answer 1

3

I think this is want you mean. Date with zero or more characters followed by 0800

egrep -lir "apples|melons|cherry" file*.txt | xargs grep -l  "Date.*0800"
0

You must log in to answer this question.

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