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 for shell loop:
for i in *.txt do fold -sw 65 $i > $i.output done
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!
- Email this to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: Nov/25/2008



{ 1 comment… read it below or add one }
Ah, this is great for grepping through a corpus of longlines-text,
gzcat corpus.txt.gz | fold | grep foo