So, I'm having a lot of crazy problems with Awk that I cannot understand. This one in particular is driving me nuts. Here is one section of my Awk script:
print $0
sub(/Jan/,"",$2)
sub(/Feb/,"",$2)
sub(/Mar/,"",$2)
sub(/Apr/,"",$2)
sub("May","",$2)
sub(/Jun/,"",$2)
sub(/Jul/,"",$2)
sub(/Aug/,"",$2)
sub(/Sep/,"",$2)
sub(/Oct/,"",$2)
sub(/Nov/,"",$2)
sub(/Dec/,"",$2)
print $0
and here is the single line that is in the datafile I am working with:
Thursday, May 29, 2014,4,11,20 PM GMT-0700,1,Hard to get mario and pokemon gamecube cases ,http,//www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube
I am trying to simply delete the word, "May", and do nothing else. I have tried this a few different ways, using a double-quoted string instead of RegExp, and the output was exactly the same. Here is the output I am getting:
Thursday, May 29, 2014,4,11,20 PM GMT-0700,1,Hard to get mario and pokemon gamecube cases ,http,//www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube
Thursday 29 2014 4 11 20 PM GMT-0700 1 Hard to get mario and pokemon gamecube cases http //www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube
You can see that after running the script, I am somehow getting a very weird result. The word "May" has been stripped from the second field, but somehow all of the commas have also been stripped from the output.
For the record I am using Gawk under Ubuntu. Any help is greatly appreciated.
---------- Post updated at 05:55 AM ---------- Previous update was at 05:43 AM ----------
Here is a more complete explanation. This is the datafile:
"Thursday, May 29, 2014","4:11:20 PM GMT-0700","1", "Hard to get mario and pokemon gamecube cases" ,"http://www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube"
This is the AWK script:
{
gsub(/\ \ /, "")
gsub(/\"/, "")
gsub(/\:/, "\,")
print $0
sub(/Jan/,"",$2)
sub(/Feb/,"",$2)
sub(/Mar/,"",$2)
sub(/Apr/,"",$2)
sub("May","",$2)
sub(/Jun/,"",$2)
sub(/Jul/,"",$2)
sub(/Aug/,"",$2)
sub(/Sep/,"",$2)
sub(/Oct/,"",$2)
sub(/Nov/,"",$2)
sub(/Dec/,"",$2)
print $0
gsub(/" AM"/, "\,AM", $4)
gsub(/" PM"/, "\,PM", $4)
gsub(/" GMT"/, "\,GMT", $4)
gsub(/\ /,"", $2)
gsub(/\ /,"", $3)
}
And, here are the two output lines, printed before and after the block of code pertaining to the months above.
Thursday, May 29, 2014,4,11,20 PM GMT-0700,1,Hard to get mario and pokemon gamecube cases ,http,//www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube
Thursday 29 2014 4 11 20 PM GMT-0700 1 Hard to get mario and pokemon gamecube cases http //www.listia.com/auction/17243312-hard-to-get-mario-and-pokemon-gamecube
The command I am using to launch awk is:
gawk -F, -f <awkfile> <datafile>
hope that helps