[Techtalk] anyone know of a simple text viewer?

Meryll Larkin mll at alwanza.com
Fri Jul 19 15:35:35 UTC 2019


Weird.  The first thing I thought was :

cat, head, tail.

for f in *.txt; do
   echo "${f}:"
   cat $f |grep -v "^$" | head -n15
   echo "-----------------"
   echo 
done

No tail in this one but it depends on what you are looking for.
For example, if you know you need to see the last few lines of a file.

Meryll


-----Original Message-----
From: Akkana Peck [mailto:akkana at shallowsky.com] 
Sent: Friday, July 19, 2019 7:54 AM
To: techtalk at linuxchix.org
Subject: Re: [Techtalk] anyone know of a simple text viewer?

> Miriam English wrote:
> > I often need to quickly look through the text files in a directory
> > without the need to edit them.

> for f in *.txt ; do leafpad "$f" ; done
> 
> This will loop through all the text files in a directory, one by one. Each
> time I press CTRL-Q to close the current window the next file opens
another
> window. It's not exactly what I was looking for, but it is close.
> 
> Anybody know a simpler solution? Preferably one that opens files in the
same
> window, one after another, and which when closed quits viewing any further
> files.

Well, I'm a commandline girl so I usually just do something like
less *.txt
which shows each file in the current terminal window.
Admittedly, less has an annoying habit of exiting if you type q
to get out of the current file, so you have to use :n to jump to
the next file. It's a little friendlier to use the same shell loop
you quoted above:

for f in *.txt ; do less "$f" ; done

Less is so much faster than opening a GUI window for each file
(is part of why I like commandline tools).

If you want it in a separate window, so (as you mention) you can
close the window to quit viewing any more files, you could open it
in another terminal:

xterm -e 'for f in .??* ; do less "$f" ; done'

(or use your favorite terminal if not xterm).

But I guess I'm not entirely clear what your goals are. What
improvements were you looking for over the leafpad solution?
Faster? Better UI for scrolling through the file?

        ...Akkana

_______________________________________________
Techtalk mailing list
Techtalk at linuxchix.org
https://mailman.linuxchix.org/mailman/listinfo/techtalk




More information about the Techtalk mailing list