Uma maneira com 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"
}
}
}' file
Teste:
$ ls
file
$ cat file
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.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
$ ls
file file_with_IPs.txt file_with_only_netmask_ips.txt
$ cat file_with_IPs.txt
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.239
$ cat file_with_only_netmask_ips.txt
255.255.0.0 255.255.255.0
255.0.0.0 255.255.0.0
255.255.255.128 255.255.255.192