-1

I have several files, namely a.txt, b.txt, c.txt, d.txt, in the same format (3 columns, separated with tab). Let's take the first 3 lines of a.txt and b.txt for example:

$head -3 a.txt
id_1 59 4
id_4 89 43
id_5 8 90

$head -3 b.txt
id_1 9 4
id_4 39 43
id_5 81 9

c.txt and d.txt are similar to that.

I want to check if the first columns from them are all the same. Is there any easy way in shell to do this?

user000001
  • 32,226
  • 12
  • 81
  • 108
Xiaokang
  • 331
  • 1
  • 11
  • 1
    What have you tried? Most of us here are happy to help you improve your craft, but are less happy acting as short order unpaid programming staff. Show us your work so far in an [MCVE](http://stackoverflow.com/help/mcve), the result you were expecting and the results you got, and we'll help you figure it out. – ghoti May 15 '17 at 12:49
  • Thank you for remind. I found online to use cmp to compare. And tried this: cmp <(cut -f1 a.txt) <(cut -f1 b.txt) <(cut -f1 c.txt) <(cut -f1 d.txt) But it didn't work. Then I realized that cmp only works for two files. Then I'm stuck with this multiple-file stuff. – Xiaokang May 15 '17 at 13:23

1 Answers1

0

With awk it would be pretty straight forward:

awk 'NR==FNR{a[FNR]=$1;next}$1!=a[FNR]{print "They are dfifferent"; exit 1}' a.txt b.txt c.txt d.txt

This assumes that we want the order of the lines to match too, If not, sort the files and repeat.

user000001
  • 32,226
  • 12
  • 81
  • 108