How could I format title which includes a date using gawk and sed?
<p>I have gawk at my disposal and I have the following text I wish to format:</p>

<pre><code>Trip.to.Washington.2004.08...
Florida.1993.12...
Aunt.Rose.2011.06...
</code></pre>

<p>I would like it to appear as follows:</p>

<pre><code>Trip to Washington (2004)
Florida (1993)
Aunt Rose (2011)
</code></pre>

<p>The number of words in the title varies as does the amount of words following the year. The separator is sometimes a white space rather than a period.</p>

<p>Edit:</p>

<p>I was able achieve the desired output using:</p>

<pre><code>echo Trip.to.Washington.2004.08... |
sed -n 's/\([0-9][0-9][0-9][0-9]\).*/\1/p' |
gawk 'BEGIN { FS="." } { print $1" "$2" "$3" ("$NF")" }'
</code></pre>

<p>Which returns:</p>

<pre><code>Trip to Washington (2004)
</code></pre>

<p>The problem is that this will fail if there are more, or less, words in the title. It will also fail if the words are separated by anything other than a period.</p>

<p>I also found it is possible to return every field except for the last field using:</p>

<pre><code>awk '{$NF=""; print $0}' file
</code></pre>

<p>Unfortunately, my experience with gawk is very limited. I haven't a clue as to how to correctly make use of this statement within my existing gawk.</p>