This is a simple Korn shell version of the Unix nl command. It displays line-numbered output.
#!/bin/ksh # # knl - Korn Shell line-numbering filter # # Initialize line number counter integer LNUM=1 # Check usage if (($# == 0)) then print "Usage: $0 file . . ." exit 1 fi # Process each file for FILE do # Make sure file exists if [[ ! -f $FILE ]] then print "$FILE: non-existent or not readable" exit 1 else # Open file for reading exec 0<$FILE # Read each line, print out with line number while read -r LINE do print "$LNUM: $LINE" ((LNUM+=1)) done fi # Reset line number counter LNUM=1 done
3.142.40.32