Skip to content

Instantly share code, notes, and snippets.

@cactaceae21
Last active January 10, 2022 12:08
Show Gist options
  • Save cactaceae21/4b2a040e85d25a6fdaa0276bd3eebf6e to your computer and use it in GitHub Desktop.
Save cactaceae21/4b2a040e85d25a6fdaa0276bd3eebf6e to your computer and use it in GitHub Desktop.
Linux One Liners #linux #sed #awk #grep
Usage: locale [OPTION...] NAME
or: locale [OPTION...] [-a|-m]
Get locale-specific information.
System information:
-a, --all-locales Write names of available locales
-m, --charmaps Write names of available charmaps
Modify output format:
-c, --category-name Write names of selected categories
-k, --keyword-name Write names of selected keywords
-v, --verbose Print more information
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

Output all unique email address in a text file

cat <file.txt> | grep -oP "([a-zA-Z0-9_\-\.\*]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})" | sort -fu

Trim leading and trailing whitespace (also mid line)

awk '{$1=$1};1'

Return header response and basic cert details from a site

curl -vvI https://gnupg.org

Return the complete certificate contents from a site

echo | openssl s_client -showcerts -servername gnupg.org -connect gnupg.org:443 2>/dev/null | openssl x509 -inform pem -noout -text

Add ZLib header to file to decompress raw

printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /tmp/data | gzip -dc >/tmp/out

For RAW Deflate add two more null bytes

"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00"

Deleting the first line only (csv with headers for example)

sed '1d' file.txt > tmpfile; mv tmpfile file.txt # POSIX
sed -i '1d' file.txt # GNU sed only, creates a temporary file
perl -ip -e '$_ = undef if $. == 1' file.txt # also creates a temporary file
sed -i .bak '1d' file.txt #BSD tail -n +2 file-in.txt > file-out.txt # using Tail

  • Email addresses
    • ([a-zA-Z0-9_\-\.\*]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})

Grep switches

  • -P, --perl-regexp
    • Interpret the pattern as a Perl-compatible regular expression (PCRE). This is experimental and grep -P may warn of unimplemented features.
  • -E, --extended-regexp
    • Interpret PATTERN as an extended regular expression (ERE, see below).
  • -i, --ignore-case
    • Ignore case distinctions, so that characters that differ only in case match each other.
  • -o, --only-matching
    • Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
  • -c, --count
    • Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.
  • -v, --invert-match
    • Invert the sense of matching, to select non-matching lines.
  • -a, --binary-files=text
    • Treat binary files as text (some encoding is treated as binary although it is still text)

AWK switches

Sort switches

  • -f
    • Ignore Case
  • -u
    • Unique

SED switches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment