bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GNU Awk 3.1.2 reading zero length files


From: Carlos J. G. Duarte
Subject: GNU Awk 3.1.2 reading zero length files
Date: Wed, 07 May 2003 10:45:40 +0100

Hi, 
It seems from gawk 3.1.1 to gawk 3.1.2 a minor optimization
was made-- skipping zero length files.

In linux, files under /proc filesystem have zero length,
are regular files and they do have contents.

I have this script (snippet) to detect if the machine
is networked or not:

#!/bin/sh
if awk '/^ *eth/ {sum += $2} END { exit(sum==0) }' /proc/net/dev; then
# networked
else
# no eth traffic
fi

It worked until gawk 3.1.1. As of gawk 3.1.2 if fails because the 
file /proc/net/dev is not even read.

$ ls -al /proc/net/dev
-r--r--r--    1 root     root            0 May  7 10:39 /proc/net/dev
$ gawk '' /proc/net/dev
[nothing]
$ cat /proc/net/dev
Inter-|   Receive [... contents]
$ sed '' /proc/net/dev 
Inter-|   Receive [... contents]

A fix for this is to have file's contents fed to gawk via stdin:
cat /proc/net/dev | gawk ''

I think this is not really a gawk bug. A regular file with 0 bytes
is supposed to be empty. Just to report anyway-- there might
be some scripts out there broking.

Best regards,

-- 
carlos




reply via email to

[Prev in Thread] Current Thread [Next in Thread]