Skip to content
Advertisement

Compare multiple columns for each row

Using a csv file, i will like to compare multiple columns to check if all values are the same or not.

First row are the headers First column is the label The constant values should be from column 2 to the end ( can be 100 columns ) for the example i put only 8 columns.

The purpose is to check that all values are the same. and when it is not, report

input file

JavaScript

output desired

JavaScript

Appreciate your support

Advertisement

Answer

awk to the rescue!

I improvised little bit. How do we know which values are correct, which are not? Popular vote, counts the occurrences and assumes majority is right. As a side benefit, if all values are different as in your “Host Id” row, nothing is reported

JavaScript

returns

JavaScript

you can remove the values printed, which I put for verification.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement