Computing.Net > Forums > Unix > Using a Period in Awk as \. - Bug?

Using a Period in Awk as \. - Bug?

Reply to Message Icon

Original Message
Name: JoeBrewski
Date: May 10, 2007 at 07:50:28 Pacific
Subject: Using a Period in Awk as \. - Bug?
OS: AIX 5.3
CPU/Ram: Power5, 40+GB
Model/Manufacturer: IBM
Comment:

Using awk, and passing in a program with the -f option, taking a gigantic input file, and trying to generate a much smaller output file (party responsible for the extract does NOT have time to modify it to do this). There are numerous fields with extraneous zeroes on the output (ex: 6.000000000 vs. just 6 or 6.0). Issue is, when I try to use \. and match, say \.000000000 and replace with \.0, it STILL does an 'any-single-character' match on the period, and I CANNOT get it to work. Example: an input of 5000000000 would generate a 0. I've also tried using single-quotes as well. Seems like a bug, or maybe I'm just misunderstanding how this SHOULD work, but I've also scoured the web and still cannot find an answer for this. Also tried using gawk to no avail.

Any Tips? Was thinking of using decimal values to loop through the fields perhaps and outputting those, or using Perl, but I strongly fear those two alternatives would take much, much, longer.

Joe

All Your Base Are Belong to Us


Report Offensive Message For Removal


Response Number 1
Name: JoeBrewski
Date: May 10, 2007 at 08:21:22 Pacific
Reply: (edit)

Note: Using the gsub function. The code:
BEGIN{FS="\|"}
gsub("\|0.000000000\|","\|0\|");
gsub("\|0.000000000$","\|0");
gsub("\|.000000000$","\|0");
gsub("\|.000000000\|","\|0\|");
gsub("\.10000000\|","\.1\|");
gsub("\.20000000\|","\.2\|");
gsub("\.30000000\|","\.3\|");
gsub("\.40000000\|","\.4\|");
gsub("\.50000000\|","\.5\|");
gsub("\.60000000\|","\.6\|");
gsub("\.70000000\|","\.7\|");
gsub("\.80000000\|","\.8\|");
gsub("\.90000000\|","\.9\|");
gsub("\.000000000\|","\.0\|");
gsub("\.000000000\|","\.0\|");
gsub("\.00000000\|","\.0\|");
gsub("\.000000000","\.0");
print }


All Your Base Are Belong to Us


Report Offensive Follow Up For Removal

Response Number 2
Name: JoeBrewski
Date: May 10, 2007 at 16:35:01 Pacific
Reply: (edit)

Scoured the web some more, used perl, and (a) It Works, and (b) Is far, far, faster than grep or sed.

Issue closed.

Joe

All Your Base Are Belong to Us


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Using a Period in Awk as \. - Bug?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge