Eric Lavarde wrote:
to check multiple files I often tend to use 'cat *somefiles*' but
What? Uck!
it's all concatenated and difficult to read, so I switch back to
Right. But that is what conCATenating all of the files does.
'head -nSOMETHINGBIG *somefiles*' but it's not optimal and I might
miss lines if a file is bigger than expected.
Instead please use a file browser such as 'less', 'more', 'most' or
possibly 'emacs', 'vim,' or other. The simplest power example is to
use 'less' to view the file.
$ less ./*
Then use ":n" and ":p" to move to the next and previous file. You will
be in a tool designed for file browsing. It will display to you the
file name. It will handle raw escape characters so that it will not
confuse your terminal. It is the right tool for the job.
Would it be possible to add an option '--header' to cat so that it
separates multiple files with headers containing filenames, exactly
like head and tail do?
No. But you can easily do so yourself by writing a very small script.
#!/bin/sh
for file in "$@"; do
echo "File: $file"
cat -- "$file"
done
It wouldn't be the behavior by default obviously so that it wouldn't
break anything.
These creeping features do break things by causing the programs to
become larger and bloated. It is death by a thousand paper cuts.
They all become straws on the camel's back. And especially when the
tool shouldn't be doing it and it should be added around it using a
script then it is especially bad.
Try using 'less'. That is a good tool for the task. If you are an
emacs person then 'dired' works well. I hear that 'vim' also has a
dired editing mode these days. And then there are many other file
browser tools too.
Bob