Question: I know this is possible, probably by using `awk`, but I can't think the solution for now.

How do I convert IP format from

```none
10.1.1.1-10.1.1.3
10.100.100.11-10.100.100.31

```

to

```none
10.1.1.1-3
10.100.100.11-31

```

Here is my attempt with `cut`, but didn't really work as expected.

```none
wolf@linux:~$ echo 10.1.1.1-10.1.1.3 | cut -d . -f 1,2,3,4
10.1.1.1-10
wolf@linux:~$ 

wolf@linux:~$ echo 10.100.100.11-10.100.100.31 | cut -d . -f 1,2,3,4
10.100.100.11-10
wolf@linux:~$ 

```

Answer: 
Here’s a generic solution using AWK, adapting to the number of common components:

```c
BEGIN {
    FS = "-"
}

NF == 2 {
    split($1, start, /\./)
    split($2, end, /\./)
    printf $1
    for (i = 1; i <= length(start); i++) {
        if (start[i] != end[i]) {
            for (j = i; j <= length(end); j++)
                printf "%s%s", (j > i ? "." : "-"), end[j]
            print ""
            next
        }
    }
    print ""
}

```

This will also handle cases like `1.2.3.4-1.2.5.6`, printing the correct range:

```
1.2.3.4-5.6

```
```
$ sed 's/-.*\./-/' file
10.1.1.1-3
10.100.100.11-31

```