Skip to content

Instantly share code, notes, and snippets.

@nguyenvietyen
Last active September 2, 2020 10:31
Show Gist options
  • Save nguyenvietyen/18660c6f3956a27a5b32942e39f50dd5 to your computer and use it in GitHub Desktop.
Save nguyenvietyen/18660c6f3956a27a5b32942e39f50dd5 to your computer and use it in GitHub Desktop.
My frequently used shell scripts

Bash Cheatsheet

This extends upon https://devhints.io/bash

CHANGELOG

Version When Who What
1.0.0 2020-09-02 Viet Yen Nguyen First version

String Manipulation

Replace part

$ export FOO=`echo "foo" | sed -e s/oo/ee/g`; echo $FOO
fee

Get column by delimiter

$ export FOO=`echo "foo,bar" | cut -d , -f 2`; echo $FOO
bar

Filtering strings

curl -s https://api.hypefactors.com/v2/categories | jq -r | grep id

Filtering strings from files recursively

egrep -rH needle *

JSON manipulation

Pretty print

curl -s https://api.hypefactors.com/v2/categories | jq

Get element(s) then as CSV

curl -s https://api.hypefactors.com/v2/categories | jq ".data[] | [.id, .name] | @csv"

Iteration

Over files

for FILE in `find .`
do
    md5sum $FILE
done

Infinite (e.g. for monitoring)

while [ true ]
do
    echo "awake"; sleep 5
done
@andreabrduque
Copy link

Please add grep cheatsheet too

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