I want to get the first string that matches my regular expression.
For example I have the String
RCPT from unknown[211.147.3.74]: 450 4.7.1 Client host rejected: cannot find your hostname, [211.147.3.74];
and my script looks like this:
IP=`echo $LINE | grep -E -o --max-count=1 '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'`
echo $IP
As result I get
211.147.3.74 211.147.3.74
But I would like to get the IP only once. I tried ‘grep –max-count=1’ but there are still two ip’s.
or from here