0

I have a CSV file with 5 columns called "in.csv":

2,3,4,5,6
12,11,13,4,44

I want to check if for each column, column(1)+column(2) == column(3) and column(4)==column(5) holds or not, using some smart Linux command.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1735076
  • 3,225
  • 7
  • 19
  • 16

1 Answers1

1

Let us take this as the sample input:

$ cat in.csv
2,3,4,5,6
12,11,13,4,44
2,3,5,8,8
2,3,5,8,9

This will print all lines for which "column(1)+column(2) == column(3) and column(4)==column(5) holds":

$ awk -F, '$1+$2==$3 && $4==$5' in.csv
2,3,5,8,8

This will print all lines for which "column(1)+column(2) == column(3)" holds while ignoring columns 4 and 5:

$ awk -F, '$1+$2==$3' in.csv
2,3,5,8,8
2,3,5,8,9

This will print all lines for which "column(1)+column(2) == column(3)" is false:

$ awk -F, '$1+$2!=$3' in.csv
2,3,4,5,6
12,11,13,4,44
John1024
  • 109,961
  • 14
  • 137
  • 171