RedPandaSpaceOdyssey
RedPandaSpaceOdyssey

Reputation: 257

awk a number, character, then the same number

I have a column of values where the field begins with n/n: and where n is a number between 0 and 20.

Other columns also contain "n/n:" information; I only want to filter based on a single specific column.

"n/n:" can be a combination of any pair of numbers between 0 and 20 (ex. 0/1:, 1/1:, 1/19:, 19/19:)

I would like to filter lines in the file where the first and second n are the same number in the column of interest (0/0, 1/1,... 20/20).

Rather than do this once for each combination of numbers (each iteration would take a long time):

awk '$col !~ /^n\/n:/' file > filtered.file

... I'm hoping there's a more concise, better way.

An example of the file

 1/1: 0/1: a
 1/2: 1/1: b
 0/1: 2/2: c
 3/3: 0/2: d
 0/2: 0/1: e

Desired output, filtered based on col2

 1/1: 0/1: a
 3/3: 0/2: d
 0/2: 0/1: e

Upvotes: 0

Views: 84

Answers (1)

karakfa
karakfa

Reputation: 67567

awk to the rescue!

UPDATED

$ awk -v col=2 '{split($col,a,"[/:]")} a[1]!=a[2]' file

 1/1: 0/1: a
 3/3: 0/2: d
 0/2: 0/1: e

Upvotes: 2

Related Questions