unix trim

February 22, 2011 at 12:01:20
Specs: Unix AIX
My source file is comma delimited and the sixth delimeter has trailing spaces. I am using the following awk command and getting 0 line count :

awk -F\, '$6 == "EXTINCT" { print }' IDCSRC.CSV|wc -l

When using the other version with trailing space I am getting correct line count back :

awk -F\, '$6 == "EXTINCT " { print }' IDCSRC.CSV|wc -l

1747512

How can i trim the 6th delimeter in the first version of the awk command to get the right number of lines ?

Thanks

Wasim


See More: unix trim

Report •

#1
February 22, 2011 at 13:24:24
awk's gsub function can remove all the spaces in field 6. Unfortunately on Solaris 9 I had to use nawk and the short hand awk notation would not work with the incusion of gsub:

awk -F"," ' { gsub("  *","",$6)
  if($6 == "EXTINCT")
     print
}' IDCSRC.CSV|wc -l


Report •
Related Solutions


Ask Question