Skip to content

Instantly share code, notes, and snippets.

@JoshRagem
Created April 2, 2018 15:50
Show Gist options
  • Save JoshRagem/18c8938fca229fdbdf2304fe2414e431 to your computer and use it in GitHub Desktop.
Save JoshRagem/18c8938fca229fdbdf2304fe2414e431 to your computer and use it in GitHub Desktop.
#!/bin/bash
READFILE=${1:-/dev/stdin}
printf "LINE_NUM\tBYTE_SUM\tCHAR_LEN\tBYTE_LEN\tLINE"
LINNUM=0
BYTE_SUM=0
O_LANG=$LANG O_LCALL=$LC_ALL
while IFS= read -r line
do
echo "$line"
LINNUM=$((LINNUM+1))
CHAR_LEN=${#line}
CHAR_LEN=$((CHAR_LEN+1)) #for newline consumed by 'read'
LANG=c LC_ALL=C
BYTE_LEN=${#line}
BYTE_LEN=$((BYTE_LEN+1)) #for newline consumed by 'read'
LANG=$O_LANG LC_ALL=$O_LCALL
BYTE_SUM=$((BYTE_SUM+BYTE_LEN))
printf "%d\t%d\t%d\t%d\t%s\n" $LINNUM $BYTE_SUM $CHAR_LEN $BYTE_LEN "$line"
done < $READFILE
#!/bin/bash
counts "$1" | awk '$2 > '$2' {print ;}' | head -n 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment