[lfs-support] A bug in gawk?

Bruce Dubbs bruce.dubbs at gmail.com
Fri Oct 11 19:48:46 PDT 2013


alex lupu wrote:
> gawk - v. <= 4.1.0
> sed - v. whatever
>
> I have a file, 'tempx.txt' containing
>   (for simplicity - some "so" files from my '/usr/lib/'),
>
> []$ cat tempx.txt
> libexpect5.43.so
> libsndfile.so.1.0.25
> libsoftokn3.so
> libsoup-2.4.so.1.5.0
>
> and I would like to separate their "roots" from the rest, i.e.,
>
> "libsndfile.so.1.0.25" --> "libsndfile", etc.
>
> so I (instinctively) try:
>
> []$ cat tempx.txt | awk 'BEGIN {FS=".so"} ; {print $1}'
> libexpect5.43
> libsndfile
> li
> li
>
> then this (to show off I know a thing or two about escapes):
>
> [/usr/lib]$ cat tempx.txt | awk 'BEGIN {FS="\.so"} ; {print $1}'
>   awk: cmd. line:1: warning: escape sequence `\.' treated as plain `.'
> libexpect5.43
> libsndfile
> li
> li
>
> Terrible.
>
> Surprisingly, this ugly hack (bringing 'sed' into the picture)
> accomplishes what I intended.
>
> First, to test the waters,
> []$ sed -e 's/\.so/YYY/' tempx.txt
> libexpect5.43YYY
> libsndfileYYY.1.0.25
> libsoftokn3YYY
> libsoup-2.4YYY.1.5.0
>
> then, finally,
>
> []$ sed -e 's/\.so/YYY/' tempx.txt | awk 'BEGIN {FS="YYY"} ; {print $1}'
> libexpect5.43
> libsndfile
> libsoftokn3
> libsoup-2.4
>
> Is there a problem with GNU gawk and/or my system or maybe with me?

You.

echo libsndfile.so.1.0.25 | sed -r 's/(.*)\.so.*/\1/'

Or

for f in `cat tempx.txt`; do echo $f | sed -r 's/(.*)\.so.*/\1/'; done

   -- Bruce



More information about the lfs-support mailing list