awk icon indicating copy to clipboard operation
awk copied to clipboard

awk: Make the historic -Ft to signify field separator as tab optional

Open bsdimp opened this issue 4 years ago • 10 comments

The historic behavior of awk has been to make -Ft mean -F\t. However, that's a bit of a wart and antiquated. Make this behavior optional based on a simple ifdef HISTORIC_FT_WART.

bsdimp avatar Jul 11 '21 00:07 bsdimp

I'll think about it. I don't like hiding this wart, it has been there for a very long time, there could be scripts that depend on this.

plan9 avatar Jul 15 '21 15:07 plan9

Given my recent experience with subtle changes causing weird breakage, I'm inclined to withdraw this request since -Ft has been a thing for so long.

bsdimp avatar Jul 16 '21 02:07 bsdimp

I will note that POSIX doesn't require this wart, and gawk only implements it with the --traditional option. I suspect it's actually a safe change. Or you might could condition it on POSIXLY_CORRECT, but that's a bit of a slippery slope.

arnoldrobbins avatar Jul 16 '21 06:07 arnoldrobbins

POSIXLY_CORRECT which POSIX?

Though it would make that other change go from a #if 0 to a #if POSIXLY_CORRECT >= 2001 && POSIXLY_CORRECT <= 2004 :) Though the later standards author clearly felt that would be more of a POSIX_MISTAKE

So while I may poke a little fun in this comment, I think that would be quite the slippery slope...

bsdimp avatar Jul 16 '21 16:07 bsdimp

That wasn't what I meant (checking POSIX at compile time). Rather, gawk pays attention to the POSIXLY_CORRECT environment variable, and if it's there, turns on the --posix option. There is one place in the OTA where this is done as well.

In this case though, POSIXLY_CORRECT doesn't really help, since POSIX doesn't require -Ft to mean FS = "\t".

Oz, IMHO it's safe to simply make the change and be done, but I'll leave it up to you. (Or you can ping BWK privately.)

arnoldrobbins avatar Jul 18 '21 13:07 arnoldrobbins

I found an unfortunate number cases of awk -Ft in github and elsewhere. that wart is better known than I thought.

plan9 avatar Jul 27 '21 20:07 plan9

For the record, how many? And how did you find them :)

bsdimp avatar Jul 27 '21 20:07 bsdimp

github code search alone finds 241 hits, [sans about a third to half of those that are "-FT".] some of our own solaris scripts have a handful of instances. didn't search other code hosting sites (not sure which ones have good code search). saw some in stackoverflow etc as well.

plan9 avatar Jul 28 '21 05:07 plan9

anyway, i suppose it is time to deprecate the t-wart.

plan9 avatar Jul 29 '21 20:07 plan9

I found an unfortunate number cases of awk -Ft in github and elsewhere. that wart is better known than I thought.

I really find this surprising. In > 30 years nobody has ever complained to me about gawk not supporting this wart. In any case, I agree that deprecating it is a good idea.

arnoldrobbins avatar Jul 30 '21 10:07 arnoldrobbins

FWIW, -Ft is no longer documented in the upcoming 2nd edition of the original awk book. I suggest leaving the code alone, since apparently people still expect it to work, but leaving it undocumented. Maybe we can close this PR?

arnoldrobbins avatar Jun 14 '23 23:06 arnoldrobbins