Advertisement
cd62131

cat -n

Apr 8th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.38 KB | None | 0 0
  1. #!/bin/bash -e
  2. typeset -i DIGIT=$(sed -n $= $1)
  3. typeset -i digit
  4. if (( DIGIT < 10 )); then digit=1
  5. elif (( DIGIT < 100 )); then digit=2
  6. elif (( DIGIT < 1000 )); then digit=3
  7. elif (( DIGIT < 10000 )); then digit=4
  8. elif (( DIGIT < 100000 )); then digit=5
  9. else exit 9
  10. fi
  11. typeset -i line_no=1
  12. while read; do
  13.   printf "%0*d %s\n" ${digit} $(( line_no++ )) "${REPLY}"
  14. done <$1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement