简体   繁体   中英

How can I split text files by counting characters and find space (without dividing words ) between 30 and 40 characters

This command splits text file by 30 characters. It also divide words but I need help for split text without divide the word find space between 30 and 40 after that split text file.

sed -e 's/.\{30\}/&\n/g' filename

Better use a proper lib, like in . The name for this is text wraping :

perl -MText::Wrap -lne '
    $Text::Wrap::columns = 30;
    print wrap("", "", $_)
' file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM