Content area
Full Text
The Linux fold takes lines of text and breaks them into chunks based on the arguments that you provide. With no arguments, fold will break lines at 80 characters.
The first example below uses a single-line text file that includes indications of character positions. First, we count the number of characters and lines in the file using the wc -l and wc -l command:
ADVERTISEMENT
$ wc -c wide_text
251 wide_text
$ wc -l wide_text
1 wide_text
So, this file has 251 characters (including a carriage return) and a single line of text. Next, we display the file using the cat command:
$ cat wide_text
.........1.........2.........3.........4.........5.........6.........7.........8.........9........10........11........12........13........14........15........16........17........18........19........20........21........22........23........24........25
Then we use the fold command to break the file into separate lines:
$ fold wide_text
.........1.........2.........3.........4.........5.........6.........7.........8
.........9........10........11........12........13........14........15........16
........17........18........19........20........21........22........23........24
........25
In the example above, a 250-character line is passed to the fold command, and it generates four lines of text – three with 80 characters and a fourth with the remaining 10.
The fold command does, however, provide the -c (characters) option to break lines into larger or smaller chunks. In the example below, we break the wide_text...