Skip to main content

Bash is hard but you can Iyou call perlPerl from bashBash? If your fields are separated by commas, and your key field is the second one,

$ cat a.csv 11,22,33 214,22,354 6,6,6 4,5,7 1,22,1 

this one liner will print if it hasn't seen the second column already:

$ perl -ne '$value = (split /,/)[1]; print unless $x{$value}++;' a.csv 11,22,33 6,6,6 4,5,7 

The [1] is the column number and is zero-based.

Bash is hard but you can I call perl from bash? If your fields are separated by commas, and your key field is the second one,

$ cat a.csv 11,22,33 214,22,354 6,6,6 4,5,7 1,22,1 

this one liner will print if it hasn't seen the second column already:

$ perl -ne '$value = (split /,/)[1]; print unless $x{$value}++;' a.csv 11,22,33 6,6,6 4,5,7 

The [1] is the column number and is zero-based.

Bash is hard but you can you call Perl from Bash? If your fields are separated by commas, and your key field is the second one,

$ cat a.csv 11,22,33 214,22,354 6,6,6 4,5,7 1,22,1 

this one liner will print if it hasn't seen the second column already:

$ perl -ne '$value = (split /,/)[1]; print unless $x{$value}++;' a.csv 11,22,33 6,6,6 4,5,7 

The [1] is the column number and is zero-based.

Source Link

Bash is hard but you can I call perl from bash? If your fields are separated by commas, and your key field is the second one,

$ cat a.csv 11,22,33 214,22,354 6,6,6 4,5,7 1,22,1 

this one liner will print if it hasn't seen the second column already:

$ perl -ne '$value = (split /,/)[1]; print unless $x{$value}++;' a.csv 11,22,33 6,6,6 4,5,7 

The [1] is the column number and is zero-based.