Gentoo Archives: gentoo-user

From: paulcol@×××××××××××××××××.au
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] how to word-wrap using a pipe?
Date: Mon, 20 Oct 2008 08:17:23
Message-Id: 20081020031931.GA25434@andor.dropbear.id.au
In Reply to: [gentoo-user] how to word-wrap using a pipe? by zhangweiwu@realss.com
1 On Mon, Oct 20, 2008 at 09:13:46AM +0800, zhangweiwu@××××××.com wrote:
2 > Hello. How can I line-wrap a text file that was not wrapped before (e.g.
3 > like text file created on Microsoft Windows's notepad, the software does
4 > softwrap by default, thus the file created using it often have very long
5 > text lines) by using command pipe?
6 >
7 > I could use vim, activate some formatting options and use gq. But that
8 > couldn't be used on a pipe.
9 >
10 > I could use groff, but that command line looks too complicated:
11 >
12 > $ head -n1 max_payne | groff -Tutf8 | grep --invert-match ^$
13 > Life was good. A house on the Jersey side across the river. The
14 > smell of freshly cut lawns. The sounds of children playing. A
15 > beautiful wife and a baby girl. The American dream come true. But
16 > dreams have a nasty habit of going bad when you’re not looking.
17 >
18 >
19 > Besides groff wraps not according to the console term width, but
20 > according to the paper size in /etc/paper. It would be nice to have
21 > something wrap my text by using console width (what you get with '$ stty
22 > -a | head -n1')
23
24
25 $ man -k wrap | fgrep line
26 Text::Wrap (3pm) - line wrapping to form simple paragraphs
27 fold (1) - wrap each input line to fit in specified width
28 ggz-wrapper (6) - GGZ Gaming Zone command line core client
29
30
31 Hmm, 'fold' looks promising...
32
33
34 $ fold --help
35 Usage: fold [OPTION]... [FILE]...
36 Wrap input lines in each FILE (standard input by default), writing to
37 standard output.
38
39 Mandatory arguments to long options are mandatory for short options too.
40 -b, --bytes count bytes rather than columns
41 -s, --spaces break at spaces
42 -w, --width=WIDTH use WIDTH columns instead of 80
43 --help display this help and exit
44 --version output version information and exit
45
46
47 --
48 Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol
49 Asking for technical help in newsgroups? Read this first:
50 http://catb.org/~esr/faqs/smart-questions.html#intro

Replies

Subject Author
Re: [gentoo-user] how to word-wrap using a pipe? Neil Bothwick <neil@××××××××××.uk>