Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active February 23, 2017 23:20
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 jpotts18/18d001121528ab05570912fbd08c5b2a to your computer and use it in GitHub Desktop.
Save jpotts18/18d001121528ab05570912fbd08c5b2a to your computer and use it in GitHub Desktop.
Thing I want to do Command
overwrite file >
append to file >>
search in file grep '??' file.csv
search in file (case insensitive) grep 'LLC' -i file.csv
search in file (show line numbers) grep ',llc,' -n file.csv
remove header tail -n +2 file.csv > new_file.csv
remove header sed 1d file.csv > new_file.csv
add header { head -1 with_header.csv; cat headerless.csv;} > new_file.csv
delete line with pattern sed '/pattern/d' file.csv > new_file.csv
delete line with pattern inline sed -i.bak '/pattern/d' file.csv > new_file.csv
delete line number sed -e '100d' file.csv
print line number sed -n 100p file.csv
print range of line numbers sed -n 98,102p file.csv
cut a set of columns from a csv with a pipe delimiter `cat file.csv
clean a csv file csvclean file.csv
change a delimter (comma to colon) sed 's/,/:/g' file.csv > out.csv
change a tsv to a csv `cat file.tsv
split a file by 1000 lines split -l 1000 file.csv
find similar lines between two files fgrep -x -f file1.csv file2.csv
find difference between two files grep -Fxvf file1 file2
unzip a chunk of a gz file `gunzip -c input.gz
delete files that are empty `find -type f -size 0 -print0
loop over files for f in *.csv; do cat $f; done
fetch remote file scp remote:/home/ubuntu/stuff.txt ~/Downloads/thing.txt

Tools

  • csvkit - A suite of utilities for converting to and working with CSV

  • jq - jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data

  • awscli - CLI for working with AWS.

  • [Explain Shell] (http://explainshell.com/)

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