Tue Apr 19 18:42:06 NZST 2005
To continue the trend set by James Clark... Here is my choice for
useful command-line tool of the day.
Fold is a simple little command line util that lets you fold lines of
text at a particular width. Eg if you have some long lines of text, say
out of some HTML or other document format that only maintains paragraph
breaks, that you want to show on a console screen you can do this:
fold -s -w 70 long-lines.txt |less
This command will fold the text from long-lines.txt at 70 characters (or
the nearest preceding space). If you leave off -s the lines will get
cut in the middle of words. Most consoles are 80 columns wide and fold
defaults to a width (-w) of 80 columns.
This can also be useful in scripts where you need to display a paragraph
of text with interpolated variables which you don't know the width of
echo -n "Enter some text: "
para="You said, '$var'. That's really interesting. But \
do you know the answer to the ultimate question of life, \
the universe, and everything?";
echo $para | fold -s -w 78 -
Oliver Jones » Roving Code Warrior
oliver@d... » +64 (21) 41 2238 » www.deeperdesign.com
More information about the wlug
NOTICE: This is an archive of a public mailing list. The University of Waikato is not responsible for its contents.