Last active
May 24, 2018 06:43
-
-
Save 7171u/b430021500b5a65ff834f65f964e2e69 to your computer and use it in GitHub Desktop.
awk Script To Fold Each Field To n Characters Per Line ( works for comma separated files - CSV)
This file contains hidden or 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
#usage awk -F"," -v fm=n -f foldfields.awk <file.csv> | column -t -s"," | |
#Where n is the fold width | |
{ | |
maxblk=1; | |
for (i=1;i<=NF;i++) { | |
blk=1; | |
while (length($i)) { | |
y[i"@"blk]=substr($i,1,fm) ; | |
blk++; | |
$i=substr($i,fm-1); | |
if( maxblk<blk)maxblk=blk | |
} | |
}; | |
for (k=1;k<=maxblk;k++) { | |
for (i=1;i<=NF;i++){ | |
if (!y[i"@"k]) { | |
printf " "FS | |
} | |
else { | |
printf y[i"@"k]""FS | |
} | |
} | |
print ""} | |
delete y | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment