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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Using a Period in Awk as \. - Bug?

Reply to Message Icon

Name: JoeBrewski
Date: May 10, 2007 at 07:50:28 Pacific
OS: AIX 5.3
CPU/Ram: Power5, 40+GB
Product: 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



Sponsored Link
Ads by Google

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

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


0

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


emacs copy question Comparison with differenc...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


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

using string variable in awk www.computing.net/answers/unix/using-string-variable-in-awk/8040.html

Shell variable in AWK www.computing.net/answers/unix/shell-variable-in-awk/6651.html

Printf in AWK www.computing.net/answers/unix/printf-in-awk/4502.html