fold: Wrap Text File / Line / Words To Fit in Specified Width
This demonstrates a bash command line tool, an equivalent php tool would be wordwrap.
fold is really nifty command line utility to make a text file word wrap. This is useful for large number of text files processing. There is no need to write a perl / python code or use a word processor.
fold command syntax
fold -sw {COUNT} {input.txt} > {output.txt}
Wrap input lines in each input.txt, writing to standard output.txt.
Where,
- -s: break at spaces
- -w: {COUNT} use COUN} as WIDTH columns instead of default 80.
For example, following command will wrap input.txt at 60 width columns:
$ fold -sw 60 input.txt > output.txt
A large number of files can be processed using a shell loop:
for i in *.txt do fold -sw 65 $i > $i.output done
Comments
Post a Comment