From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1KrlJ5-00053F-9q for garchives@archives.gentoo.org; Mon, 20 Oct 2008 03:19:47 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 56057E02A8; Mon, 20 Oct 2008 03:19:45 +0000 (UTC) Received: from tux.andor.dropbear.id.au (unknown [124.189.38.11]) by pigeon.gentoo.org (Postfix) with ESMTP id AA79DE02A8 for ; Mon, 20 Oct 2008 03:19:44 +0000 (UTC) Received: by tux.andor.dropbear.id.au (Postfix, from userid 1000) id 75BA5AF934F; Mon, 20 Oct 2008 14:19:31 +1100 (EST) Date: Mon, 20 Oct 2008 14:19:31 +1100 From: paulcol@andor.dropbear.id.au To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] how to word-wrap using a pipe? Message-ID: <20081020031931.GA25434@andor.dropbear.id.au> References: <48FBDB4A.9070109@realss.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <48FBDB4A.9070109@realss.com> User-Agent: Mutt/1.5.16 (2007-06-09) Content-Transfer-Encoding: quoted-printable X-Archives-Salt: bcfb3be9-dde7-4dd9-9b3b-4e24ba920956 X-Archives-Hash: e92315812125586252405caff9b78b4f On Mon, Oct 20, 2008 at 09:13:46AM +0800, zhangweiwu@realss.com wrote: > Hello. How can I line-wrap a text file that was not wrapped before (e.g= . > like text file created on Microsoft Windows's notepad, the software doe= s > softwrap by default, thus the file created using it often have very lon= g > text lines) by using command pipe? >=20 > I could use vim, activate some formatting options and use gq. But that > couldn't be used on a pipe. >=20 > I could use groff, but that command line looks too complicated: >=20 > $ head -n1 max_payne | groff -Tutf8 | grep --invert-match ^$ > Life was good. A house on the Jersey side across the river. The > smell of freshly cut lawns. The sounds of children playing. A > beautiful wife and a baby girl. The American dream come true. But > dreams have a nasty habit of going bad when you=E2=80=99re not lookin= g. >=20 >=20 > Besides groff wraps not according to the console term width, but > according to the paper size in /etc/paper. It would be nice to have > something wrap my text by using console width (what you get with '$ stt= y > -a | head -n1') $ man -k wrap | fgrep line Text::Wrap (3pm) - line wrapping to form simple paragraphs fold (1) - wrap each input line to fit in specified widt= h ggz-wrapper (6) - GGZ Gaming Zone command line core client Hmm, 'fold' looks promising... $ fold --help Usage: fold [OPTION]... [FILE]... Wrap input lines in each FILE (standard input by default), writing to standard output. Mandatory arguments to long options are mandatory for short options too. -b, --bytes count bytes rather than columns -s, --spaces break at spaces -w, --width=3DWIDTH use WIDTH columns instead of 80 --help display this help and exit --version output version information and exit --=20 Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol Asking for technical help in newsgroups? Read this first: http://catb.org/~esr/faqs/smart-questions.html#intro