1

I have a 30 000+ line CSV file and I do not need most of it. It comes from my supplier and I only want the lines that have value greater then 1 so the lines with 0 in the 6th column that shows quantity of 1 or more I want it to print.

So I am noticing with the awk command I get weird data and someone tells me it is because of the leading space in front of the 0 in the 6th column

awk '{ print $6 }'
2.1
Link
LAN
SATA
and
2U
SATA
1U
... goes on forever

Is there a way to filter out all the useless lines!

Here is my attempt to do this

awk -F '$6 <= 1 {print $0}' 

Here are a few lines

100005,PC-Q08A,Lian-Li Case PC-Q08A Mini Tower 1/0/6 FAN Aluminum USB3.0 Silver Mini-ITX Retail,Lian-Li,CS, 0,145.98,7.92,EA,LB,CSB,ACTIVE,840353002388

100006,PC-Q08B,Lian-Li Case PC-Q08B Mini Tower 1/0/6 FAN Aluminum USB3.0 Black Mini-ITX Retail,Lian-Li,CS, 0,127.28,7.92,EA,LB,CSB,ACTIVE,840353002395

100011,EAH5450SILENT/DI/1GD3(LP),Asus Video Card ATI Radeon HD 5450 1GB DDR3 64Bit Low Profile Silent PCI-Express 2.1 DVI-I/HDMI/HDCP Retail,ASUS TeK,VC, 64,43.93,0.90,EA,LB,V1G,ACTIVE,610839367436

100012,E783686,EloTouch LCD 19inch 1919L E783686 IntelliTouch VGA 1000:1 5m Dark Gray Retail,Elo TouchSystems,MN, 0,748.84,21.50,EA,LB,ML9,ACTIVE,NA

The 3rd line has quantity 64 and that line I want; the rest I do not. Note its the 6th field in the 3rd line that is 64.

1
  • 1
    You need to actually put the comma you are using as a separator in the statement awk -F',' '$6>0' file Aug 16, 2015 at 21:27

1 Answer 1

3

It looks to me like you just left out the "," argument to -F, and also have the comparison backwards. (And it's not incorrect, but you don't really need the {print $0} since that's the default action.)

$ cat file.txt
100005,PC-Q08A,Lian-Li Case PC-Q08A Mini Tower 1/0/6 FAN Aluminum USB3.0 Silver Mini-ITX Retail,Lian-Li,CS, 0,145.98,7.92,EA,LB,CSB,ACTIVE,840353002388
100006,PC-Q08B,Lian-Li Case PC-Q08B Mini Tower 1/0/6 FAN Aluminum USB3.0 Black Mini-ITX Retail,Lian-Li,CS, 0,127.28,7.92,EA,LB,CSB,ACTIVE,840353002395
100011,EAH5450SILENT/DI/1GD3(LP),Asus Video Card ATI Radeon HD 5450 1GB DDR3 64Bit Low Profile Silent PCI-Express 2.1 DVI-I/HDMI/HDCP Retail,ASUS TeK,VC, 64,43.93,0.90,EA,LB,V1G,ACTIVE,610839367436
100012,E783686,EloTouch LCD 19inch 1919L E783686 IntelliTouch VGA 1000:1 5m Dark Gray Retail,Elo TouchSystems,MN, 0,748.84,21.50,EA,LB,ML9,ACTIVE,NA194170,46.9,42.2


$ awk -F, '$6 >= 1' file.txt
100011,EAH5450SILENT/DI/1GD3(LP),Asus Video Card ATI Radeon HD 5450 1GB DDR3 64Bit Low Profile Silent PCI-Express 2.1 DVI-I/HDMI/HDCP Retail,ASUS TeK,VC, 64,43.93,0.90,EA,LB,V1G,ACTIVE,610839367436

With respect to the weird data you're seeing for the 6th field, again, you were missing the field separator argument:

$ awk -F, '{ print $6 }' file.txt
0
0
64
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.