coreutils
[Top][All Lists]
Advanced

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

Re: Extend cat to have headers like head/tail


From: Eric Lavarde
Subject: Re: Extend cat to have headers like head/tail
Date: Sat, 11 May 2013 09:21:44 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130413 Icedove/17.0.5

Hi,

a simple "no, it will bloat the code" would have done it as well :-P

Yep, I'll resort to a script.

Thanks, Eric

On 10/05/13 18:29, Bob Proulx wrote:
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





reply via email to

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