Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9996

FIELDWIDTHS helper

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Bruce <07.013@scorecrow.com>
Newsgroups comp.lang.awk
Subject FIELDWIDTHS helper
Date Wed, 6 Aug 2025 10:23:10 +0100
Organization A noiseless patient Spider
Lines 26
Message-ID <b208cecc-acca-4a4b-bce8-013c66682fcc@scorecrow.com> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Wed, 06 Aug 2025 09:23:12 +0000 (UTC)
Injection-Info dont-email.me; posting-host="59497e50ab97a8f24682102a50b08b24"; logging-data="3462760"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PNp2qsmVyuZO/loCiEJRWI+dPoTm+OLg="
User-Agent Mozilla Thunderbird
Cancel-Lock sha1:IpF1cdJP3fhCdZMRY7OqMCXLNzg=
Content-Language en-GB
Xref csiph.com comp.lang.awk:9996

Show key headers only | View raw


The other day I found myself unable to count field sizes accurately so I
wrote this little helper.

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

-- 
Bruce Horrocks
Hampshire, England

Back to comp.lang.awk | Previous | NextNext in thread | Find similar


Thread

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