IN: 1234567890123456 abcdefghijklmnop The quick brown OUT: 123|456789|01|23456 abc|defghi|jk|lmnop The| quick| b|rown
sed -n
's/[^0-9]*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p'
infile > outfile
string read as explanation s "substitute" / delimiter start of pattern [^0-9]* non-digits need not be anchored to '^'; use of ".*" would take away from the following digits! \( "start group" - start of IP number [0-9]\{1,3\} a number at least one, at most three digits \. a literal dot seperating the numbers [0-9]\{1,3\} a number at least one, at most three digits \. a literal dot seperating the numbers [0-9]\{1,3\} a number at least one, at most three digits \. a literal dot seperating the numbers [0-9]\{1,3\} a number at least one, at most three digits \) "end group" end of IP number .* "everything" this should match the rest of the line / delimiter separates input pattern from substitution pattern \1 first group references the matched first group this should contain the IP number / delimiter separates input pattern from p "print" prints the output pattern (default)
Here it is:
Again, this is fairly simple: