Say I have the following structure of files and directories:
$ tree
.
├── a
├── b
└── dir
└── c
1 directory, 3 files
That is, two file
If you wanted to safeguard your script from other people mistakenly passing a directory (or anything else that's not a readable text file) to it, you could do this:
$ ls -F tmp
bar dir/ foo
$ cat tmp/foo
line 1
$ cat tmp/bar
line 1
line 2
$ cat tmp/dir
cat: tmp/dir: Is a directory
$ cat tst.awk
BEGIN {
for (i=1;i
Per POSIX getline
returns -1
if/when it fails trying to retrieve a record from a file (e.g. unreadable file or file does not exist or file is a directory), you just need GNU awk to tell you which of those failures it was by the value of ERRNO
if you care.