Skip to content

Instantly share code, notes, and snippets.

@packetchef
Created August 1, 2020 16:34
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 packetchef/00172ba64a121b61b276607e45dfc59d to your computer and use it in GitHub Desktop.
Save packetchef/00172ba64a121b61b276607e45dfc59d to your computer and use it in GitHub Desktop.
# How many characters per line?
$ awk '{ print length($0) }'
# How many words per line? Add -F for separator
awk '{ print NF }'
# How do I see a substring? Example, 4 characters starting at position 2
$ awk '{ print substr($0, 2, 4) }'
# Alternative to the above, use cut:
$ cut -c2-4
# Where is my substring?
$ awk '{ print index($0, "string") }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment