Compare two files using Shellscript

1

I have a number of data collectors connected to a service. This service is provided by third parties and I do not have "admin" access to create the queries in my interest. The only way to know if these collectors are active is via a URL that returns me pure text with the IP addresses of the devices:

["/10.0.0.110","/10.0.0.119","/10.0.0.130","/10.0.0.114"/10.0.0.110","/10.0.0.119"]

This format is bad for the end user, often comes duplicate addresses, would need something more friendly (I have 20 of those, if you have a disconnected one, it looks bad to identify and I do not want to be tied to this task to verify) / p>

I was able to handle "file1" to stay this way (single and sequential values)

10.0.0.110
10.0.0.113
10.0.0.119
10.0.0.130

However, as we know users tend to be lazy to relate the numbers. I have a "table2" with the following data:

10.0.0.110 ---> coletor A
[...]
10.0.0.130 ---> coletor R

I would like some suggestion to compare the occurrences in file1 and table2. The expected return would be something like:

10.0.0.110 --> coletor A
10.0.0.113 --> coletor D
10.0.0.119 --> coletor H
10.0.0.130 --> coletor R

Thank you in advance.

I was able to solve with the tip of the friend @JJoao.

$join arquivo1 tabela2 > combinados

"join" requires that the files are ordered in ascending order. To do this use:

$cat arquivo |sort |uniq > arquivo1
    
asked by anonymous 22.03.2018 / 19:10

1 answer

0

The following is the solution to the problem. I was able to solve using the tip that @JJaoao gave: The "join" requires the files to be sorted in ascending order. To do this use:

$cat arquivo |sort |uniq > arquivo1

Example of using the "join" command:

$join arquivo1 tabela2 > combinados
  

$ man join

     

join - join lines of two files on a common field

     

SYNOPSIS          join [OPTION] ... FILE1 FILE2

     

DESCRIPTION For each pair of input lines with identical join fields,   write a line to standard output. The default join field is the first,   delimited by whitespace. When FILE1 or FILE2 (not both) is -, read   standard input.

    
26.03.2018 / 17:17