Dhunt90
Dhunt90

Reputation: 81

Using Awk to print a column if only it meets criteria

I have a file called autodata.csv and has 20 columns of data. I am looking to print only the rows with "6" being in column 8 (for cylinders).

So, I have this working but only printing the number 6, rather than all the columns:

#!/bin/bash

while read x
do

echo $x | awk -F ',' ' { print $8=6} '

done

But if I add the rest of the columns it gives me errors:

echo $x | awk -F',' ' { print $1":"$2":"$4":"$7":"$8=6}'

Upvotes: 0

Views: 867

Answers (2)

cnicutar
cnicutar

Reputation: 182734

How about:

awk -F ',' '$8 == "6" {print $0}'

Upvotes: 2

phs
phs

Reputation: 11061

Something like this, perhaps?

awk -F ',' '{ if ($8 == 6) { print $1":"$2":"$4":"$7":"$8 } }'

Upvotes: 3

Related Questions