I have file with IP address and netmask IP'smy target is to cut the netmask IP's from the file_with_IPs.txt and paste them to another file as file_with_only_netmask_ips.txtremark - netmask IP can be any combination of netmask IP , and can start for example from xxx.xxx.xxx.xxx/1 until xxx.xxx.xxx.xxx/32 for example  10.140.4.11    10.140.4.110      255.255.0.0    255.255.255.0      10.219.39.188  10.219.39.200  10.219.39.189  10.219.39.145  10.140.4.12    10.140.4.120  10.219.39.138   10.219.39.140  10.219.39.139   10.219.39.239  255.0.0.0        255.255.0.0  255.255.255.128    255.255.255.192so finally I will have in file_with_IPs.txt file  10.140.4.11    10.140.4.110      10.219.39.188  10.219.39.200  10.219.39.189  10.219.39.145  10.140.4.12    10.140.4.120  10.219.39.138   10.219.39.140  10.219.39.139   10.219.39.239and in file_with_only_netmask_ips.txt I will have only the netmask IPs as the following:  255.255.0.0    255.255.255.0  255.0.0.0        255.255.0.0  255.255.255.128    255.255.255.192Please advice what the best way to separate the netmask IPs from the ordinary IP's ?I need to write the procedure with ksh shell , and I need to run this process on Linux and Solaris machinesremark perl one linear , sed and awk can be in ksh script
linux & solaris - separate netmask IP's from ordinary IP's
linux;sed;solaris;perl;ksh
One way with awk: awk '{    for(i=1;i<=NF;i++) {        if($i~/^255/) {            netmask[NR]=i>1?netmask[NR]\t$i:$i        }        else {             regular[NR]=i>1?regular[NR]\t$i:$i        }    }}END {    for(i=1;i<=NR;i++) {        if (regular[i]) {            print regular[i] > file_with_IPs.txt        }        if (netmask[i]) {            print netmask[i] > file_with_only_netmask_ips.txt        }    }}' fileTest:$ lsfile$ cat file10.140.4.11    10.140.4.110    255.255.0.0    255.255.255.0    10.219.39.188  10.219.39.20010.219.39.189  10.219.39.14510.140.4.12    10.140.4.12010.219.39.138   10.219.39.14010.219.39.139   10.219.39.239255.0.0.0        255.255.0.0255.255.255.128    255.255.255.192$ awk '{>     for(i=1;i<=NF;i++) {>         if($i~/^255/) {>             netmask[NR]=i>1?netmask[NR]\t$i:$i>         }>         else { >             regular[NR]=i>1?regular[NR]\t$i:$i>         }>     }> }> END {>     for(i=1;i<=NR;i++) {>         if (regular[i]) {>             print regular[i] > file_with_IPs.txt>         }>         if (netmask[i]) {>             print netmask[i] > file_with_only_netmask_ips.txt>         }>     }> }' file$ lsfile  file_with_IPs.txt  file_with_only_netmask_ips.txt$ cat file_with_IPs.txt 10.140.4.11     10.140.4.11010.219.39.188   10.219.39.20010.219.39.189   10.219.39.14510.140.4.12     10.140.4.12010.219.39.138   10.219.39.14010.219.39.139   10.219.39.239$ cat file_with_only_netmask_ips.txt 255.255.0.0     255.255.255.0255.0.0.0       255.255.0.0255.255.255.128 255.255.255.192