Search code examples
regexbashcut

how to strip IP address of trailing string


Given an IP address 192.168.10.21.somebody.com.br I need to extract just 192.168.10.21 I tried CUT below, it gives "cut: invalid byte or field list".

cut -d'.' -f-4


Solution

  • $ echo "192.168.10.21.somebody.com.br" | cut -d'.' -f -4
    192.168.10.21
    

    works for me!