Unix filter "wrap"

is there one?

something that I could use as follows:

$ cat someFileWithLongLines.txt | wrap -80 --indent|less
+3
source share
6 answers

GNU coreutils has a command called fmt:

$ fmt -40 -t lorem
Lorem ipsum dolor sit amet, consectetur
   adipisicing elit, sed do eiusmod
   tempor incididunt ut labore et
   dolore magna aliqua. Ut enim
   ad minim veniam, quis nostrud
   exercitation ullamco laboris
   nisi ut aliquip ex ea commodo
   consequat. Duis aute irure dolor
   in reprehenderit in voluptate velit
   esse cillum dolore eu fugiat nulla
   pariatur. Excepteur sint occaecat
   cupidatat non proident, sunt in
   culpa qui officia deserunt mollit
   anim id est laborum.

: , fmt . fold. , fmt , , ( -t) pr, margin:

fmt -40 lorem | pr -To 6
+11

fold.

$ fold -w 80 file.txt

$ cat file.txt | fold
+6

pr, , .

$ fold -w 76 -s file.txt | pr -T --indent=4
+2

"fold", . awk .

+1

fold.

$cat someFileWithLongLines.txt |

+1

awk

width=10
awk -vw="$width" '{
    i=1
    while( length(substr($0,i,w) ) ){
        print substr($0,i,w)
        i+=w
    }
}' file

:

$ more file
this is a line 1
this is a line 2
$ fold -w 10 file
this is a
line 1
this is a
line 2
$ ./shell.sh
this is a
line 1
this is a
line 2
0

Source: https://habr.com/ru/post/1726537/


All Articles