Skip to content

Instantly share code, notes, and snippets.

@Wolfr
Created June 8, 2012 09:09
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 Wolfr/2894637 to your computer and use it in GitHub Desktop.
Save Wolfr/2894637 to your computer and use it in GitHub Desktop.
NUMBERING:
# number each line of a file (simple left alignment). Using a tab (see
# note on '\t' at end of file) instead of space will preserve margins.
sed = filename | sed 'N;s/\n/\t/'
# number each line of a file (number on left, right-aligned)
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
# number each line of file, but only print numbers if line is not blank
sed '/./=' filename | sed '/./N; s/\n/ /'
# count lines (emulates "wc -l")
sed -n '$='
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment