Hi,
I have lines that have pattern like this.
1)
productFamilyGroupIndex < Local.ProductFamilyGroup.capacity))
and
2)
if (local.getProductFamilyGroup().size() >= Local.ProductFamilyGroup.
capacity)
So, If I need to find the pattern
grep '\(< \|>= \)Local.*capacity' filename
would search only one line.
But, I want it to print 1) and 2) as well. How can I do that?
I have also tried
pcregrep '(< |>= |> |<= )Local.*(capacity|\n.*capacity)' OscCabCreatePaSaNtwrkDenrm.java
egrep '(< |>= |> |<= )Local.*(capacity|\n.*capacity)' OscCabCreatePaSaNtwrkDenrm.java
if you have gun grep, then you can try below
grep -A 2 <pattern to be searched> <file name>
grep -A2 would print only the matching line and the next line
grep '\(< \|>= \)Local.*capacity' filename -A2
will still print 1) and the next line.
But, it will not print 2) because the line 1 on 2) doesn't match.
I am looking for the pattern that matches 1) and 2)
1) and 2) are not subsequent lines. They are present at different locations in the code.
---------- Post updated at 03:52 PM ---------- Previous update was at 03:33 PM ----------
pcregrep -M '(< |>= |> |<= )Local.*(capacity|.$\n[ ]*capacity)' OscCabCreatePaSaNtwrkDenrm.java
From the man page of pcregrep
In particular, the -M option makes it possible to search for patterns that span line boundaries. What defines a line boundary is controlled by the -N (--newline) option
sed concoction:
sed -n '/Local\..*capacity/{p;d;};/Local\./{N; /Local\..*capacity/p;}' infile
I made some modifications to it, but I like the sed alternative. Thanks!