Skip to content

Instantly share code, notes, and snippets.

@kannangce
Last active March 15, 2019 05:25
Show Gist options
  • Save kannangce/994eb783aaa1cb16671a3356ad519cee to your computer and use it in GitHub Desktop.
Save kannangce/994eb783aaa1cb16671a3356ad519cee to your computer and use it in GitHub Desktop.
Contains quick command line utils that will be required for some scenarios that I faced. Some times the equivalent site I used is also mentioned

Start all the docker containers

docker ps -a|tail -n +2|awk '{print $1}'|xargs docker start

Diff

This gives side-by-side diff.

diff -y file_1 file_2

Deduplicate

pbpaste|sort|uniq -i|pbcopy

jsonformatter

pbpaste|jq .|pbcopy

xmlvalidation

'pbpaste|xmllint --format -'

Base64 decode

pbpaste|base64 --decode|pbcopy

Base64 encode

pbpaste|base64|pbcopy

Command line http server

This can be used for quick intranet file sharing. The below command starts an http server in the current folder and the contents will be served at the configured port via HTTP.

python -m SimpleHTTPServer 9090

Replace ' to " and format JSON

In languages like python, the Dict representing a JSON will have single quotes, if the dicts are just printed to log and we have to make convert it to JSON, we need to be convert it to double quotes. The below command will be useful. pbpaste|sed "s/'/\"/g"|jq .|pbcopy

Count the number of lines

Had to write a small python lib, just curious to know the number of lines it had, the below one lines that I wrote was helpful,

find ./sdk -name '*py' -exec wc -l {} \;|cut -d'.' -f1|awk '{sum+=$1;} END {print sum}'

Explanation:

  • The find part will get all the required files and gets the line count.

  • Now we will have the total lines for each files available, with cut part we will get only the line counts of the files.

  • The awk part sums all the line counts that we got and prints it. For begineers this part will be bit tricky for beginners. Refer this for more info

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