Groups | Search | Server Info | Login | Register
Groups > comp.lang.awk > #10009
| From | Janis Papanagnou <janis_papanagnou+ng@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: FIELDWIDTHS helper |
| Date | 2025-08-11 11:51 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <107ceeb$2fa2b$1@dont-email.me> (permalink) |
| References | <b208cecc-acca-4a4b-bce8-013c66682fcc@scorecrow.com> |
On 06.08.2025 11:23, Bruce wrote:
> The other day I found myself unable to count field sizes accurately so I
> wrote this little helper.
It's nice, but it should at least be mentioned that it supports only
the subset of GNU Awk's FIELDWIDTHS syntax variants as you depicted
it; like "1 3 5". While the optional final '*' would be no issue -
since the purpose is obviously to create the correct numbers for the
FIELDWIDTHS variable - the optional "skip-space" specification might
be an issue.
For example; for you sample data "A dummy line from a file" I suppose
you'd want to rather obtain a FIELDWIDTHS = "1 1:5 1:4 1:4 1:1 1:4";
and the helper doesn't help you here. (Although an extension of your
tool could be written.)
Some of the confusion that was reported in this thread could likely
have been alleviated by a better fitting data sample. Maybe
FIELDWIDTHS = "1 5 4 4 1 4" # test spec
ADummyLineFromAFile # input
1222223333444456666 # output
would have made the intention clearer.
Janis
> NR == 1 { # Pick a line
> print
> nf = split(FIELDWIDTHS, fw)
> for (i = 1; i <= nf; i++)
> for (j = 1; j <= fw[i]; j++)
> printf "%d", (i % 10)
> print ""
> }
>
>
> Example:
>
> with FIELDWIDTHS = "1 3 5"
>
> Output:
>
> A dummy line from a file
> 122233333
>
Back to comp.lang.awk | Previous | Next — Previous in thread | Find similar
FIELDWIDTHS helper Bruce <07.013@scorecrow.com> - 2025-08-06 10:23 +0100
Re: FIELDWIDTHS helper Ed Morton <mortonspam@gmail.com> - 2025-08-10 14:25 -0500
Re: FIELDWIDTHS helper Kaz Kylheku <643-408-1753@kylheku.com> - 2025-08-10 19:51 +0000
Re: FIELDWIDTHS helper gazelle@shell.xmission.com (Kenny McCormack) - 2025-08-10 21:34 +0000
Re: FIELDWIDTHS helper Kaz Kylheku <643-408-1753@kylheku.com> - 2025-08-11 04:10 +0000
Re: FIELDWIDTHS helper Bruce <07.013@scorecrow.com> - 2025-08-15 08:14 +0100
Re: FIELDWIDTHS helper Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-08-11 11:51 +0200
csiph-web