[Cialug] Display file contents either with less or cat based on number of lines

Scott Prader sprader at iastate.edu
Tue Oct 25 09:21:50 CDT 2011


Could probably write a wrapper for cat (maybe call it dog) and have it
reference /etc/mine.types and/or the file command so that once it
understands the 'scent' of the file, it will know how to process the file
based off of the preferred application for it.  For instance, if you ran the
command:

dog kitty.jpg

, it should know to figure out that it's an image file (file kitty.jpg),
check the environment (is ${DISPLAY} set?), figure out which application to
use (cross reference with mime.types depending on the environment), and run
the appropriate command to display the image.

-Scott
On Oct 25, 2011 7:29 AM, "Todd Walton" <tdwalton at gmail.com> wrote:

> Now this is clever...
>
> Display file contents either with less or cat based on number of lines:
>
> http://www.commandlinefu.com/commands/view/9571/display-file-contents-either-with-less-or-cat-based-on-number-of-lines?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Command-line-fu+%28Command-Line-Fu%29&utm_content=Google+Reader
>
> out() { tmp=$(mktemp); awk '{print $0}' > $tmp; if [ $(wc -l $tmp |
> awk '{print $1}') -gt $(tput lines) ]; then less $tmp; else cat $tmp;
> fi; rm -fr $tmp; }
>
> I mean, not clever for the command line itself, I haven't tried it yet
> (about to).  But clever because I have often wanted to do just this
> thing.
>
> I also have often wished for a command that would just show the
> contents of a file in a meaningful way based on the file type, instead
> of me having to determine the file type first.  'cat' makes sense for
> text files, but not for spreadsheets, for example.
>
> --
> Todd
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cialug.org/pipermail/cialug/attachments/20111025/8c4d4743/attachment.html>


More information about the Cialug mailing list