Skip to content

Using the Linux fold command to break text into chunks or to drive a loop

The Linux fold command enables you to break a string of characters into same-size chunks, but it can also be used to provide a series of characters or strings to drive a loop. This post reviews the basic command and then demonstrates how you can use it to loop through the characters or strings that it creates.

The basic use of the fold command is to take long lines of text and break them into shorter pieces. One common use is to shorten lines in a text file so that they display well in a terminal window. Lines wider than the terminal width might otherwise wrap in inconvenient places.

The fold command can also be used to create a narrower file from a file with lines that are inconveniently long.

To read this article in full, please click here

Source:: Network World – Data Center