img

Shell: How to wrap text files to fit specified width

September 8, 2019

You can use command called fold. It wrap each input line (or lines from file) to fit in specified width. Width can be specified in columns or bytes size. By default Wrap input lines in each FILE from standard input (keyboard ), writing to standard output (screen).

Syntax
fold -b size -w width file-name

Where,

  • -b : Use bytes rather than columns
  • -w : use WIDTH columns instead of 80 (which is default)

Examples

$ fold -w 40 file.txt
$ cat file.txt | grep something | fold -b 20

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Article Tags:
Article Categories:
How To

Comments are closed.