How to find a list of ip addresses in another file

后端 未结 3 410
我在风中等你
我在风中等你 2020-12-22 07:21

I was given the task to see if we are advertising a list of ip addresses(3000). Not a good idea to do it manually, so I copied all the ip addresses that we are advertising i

3条回答
  •  悲哀的现实
    2020-12-22 07:59

    If you sort the two files, you can use the comm command:

    sort all_ip_addresses > all_ip_addresses_sorted
    sort adverted_ip_address > advertised_ip_address_unsorted
    
    comm -23 all_ip_addresses_sorted advertised_ip_addresses_sorted
    

    will show the IP addresses that are not advertised, and:

    comm -12 all_ip_addresses_sorted advertised_ip_addresses_sorted
    

    will show the advertised IP addresses.

    You can also avoid creating the separate sorted files by using process substitution:

    comm -23 <(sort all_ip_addresses) <(sort advertised_ip_addresses)
    

提交回复
热议问题