I am trying to match multiple ip addresses, 100.x..x.x and 13.19.x.x

here is my syntax.

for item in `cat s3`
egrep -o '100\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | 13\.19\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $item

I am reading IPs from file s3 and then trying to match multiple IP address pattern. I don't know what is going wrong. Is the syntax for egrep correct?

  • We don't know either since you haven't shown us what you are trying to parse. Please edit your question and i) show us an example of s3 and ii) show us your desired output. – terdon Oct 16 '15 at 22:35
  • at first glance, the space characters around the | are likely to be a problem. depends on the input file. – cas Oct 16 '15 at 22:37
  • 2
    grep -o '1\(00\.[0-9]\{1,3\}\|3\.19\)\(\.[0-9]\{1,3\}\)\{2\}' s3 – Costas Oct 16 '15 at 22:38
  • Implicit in the last comment - you're currently asking grep to search a file called $item repeatedly, for each value $item takes. You can give the original file directly to grep and avoid the loop. If you need to extract entries from the file in that way, edit in more detail of the problem. – Michael Homer Oct 17 '15 at 0:37
  • @MichaelHomer I have tried what you just mentioned above. – Swatesh Pakhare Oct 17 '15 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.