<h1 id="basic-usage">Basic usage</h1>
<p>Use the <code>FIELDWIDTHS = &quot;n1 n2 n3 ...&quot;</code> annotation in the <code>BEGIN</code> section of an awk command to specify the widths of the fields.</p>
<p>For instance, the following file has widths of 20, 10, and 12 characters.</p>
<pre><code>NAME                STATE     TELEPHONE
John Smith          WA        418-311-4111
Mary Hartford       CA        319-219-4341
Evan Nolan          IL        219-532-5301
Boris Ratinski      NC        201-553-5555
</code></pre>
<p>Below is an example of processing such a file:</p>
<pre><code>BEGIN  { FIELDWIDTHS = &quot;20 10 12&quot; }
NR &gt; 1 {
    name = $1
    state = $2
    phone = $3
    sub(/ +$/, &quot;&quot;, name)
    sub(/ +$/, &quot;&quot;, state)
    sub(/ +$/, &quot;&quot;, phone)
    printf(&quot;%s lives in %s. The phone number is %s.\n&quot;, name, state, phone)
}
</code></pre>
<p>Then you can run the command:</p>
<pre><code>awk -f process_fixed_width.awk fixed_width.txt
</code></pre>
