[Cialug] Display file contents either with less or cat based on number of lines
Todd Walton
tdwalton at gmail.com
Tue Oct 25 07:29:20 CDT 2011
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
More information about the Cialug
mailing list