Rexxer

Some tips for me and other

Extract a text between delimiters with sh instead of using regex

Example file:

UNKNOWN[123.21.181.4]
abts-tn-dynamic-161.155.174.122.airtelbroadband.in[122.174.155.161]
fm-dyn-118-137-18-160.fast.net.id[118.137.18.160]
UNKNOWN[118.69.71.76]
ip-177.71.93.43.juniornet.psi.br[177.71.93.43]
UNKNOWN[210.245.34.254]
UNKNOWN[185.140.242.41]

I want to extract IP-addresses:

command shell:

cat drop.txt | cut -d'[‘ -f2 | cut -d’]’ -f1

  1. Get data from the file
  2. Delete all the text before the delimeter (we choose the text after the delimiter)
  3. Delete alle the text after the delimeter ( … before the delimeter)

The result:

123.21.181.4
122.174.155.161
118.137.18.160
118.69.71.76
177.71.93.43
210.245.34.254
185.140.242.41

Comments are currently closed.