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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.