Skip to content

Instantly share code, notes, and snippets.

@jnovack
Created September 9, 2018 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnovack/825b61a60a0c57cdf45396c0e3bf9318 to your computer and use it in GitHub Desktop.
Save jnovack/825b61a60a0c57cdf45396c0e3bf9318 to your computer and use it in GitHub Desktop.
awk word-wrap / trim at certain number of columns
!/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 {
print
}
'\'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment