Created
September 9, 2018 20:42
-
-
Save jnovack/825b61a60a0c57cdf45396c0e3bf9318 to your computer and use it in GitHub Desktop.
awk word-wrap / trim at certain number of columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/bin/bash | |
# `export WIDTH=120` to change the width | |
## awk-wrap | |
alias wrap='awk -v WIDTH="${WIDTH:-72}" '\'' | |
{ | |
gsub("\t"," ") | |
$0 = line $0 | |
while (length <= WIDTH) { | |
line = $0 | |
more = getline | |
gsub("\t"," ") | |
if (more) | |
$0 = line " " $0 | |
else | |
$0 = line | |
break | |
} | |
while (length >= WIDTH) { | |
print substr($0,1,WIDTH) | |
$0 = substr($0,WIDTH+1) | |
} | |
line = $0 " " | |
} | |
END { | |
} | |
'\''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment