Quick codes
A little bucket of one-liners to do clever things in the terminal
text manipulation
# head and tail
$ head -n 5 # first 5 lines
$ head # first 10 lines
# cut
$ cut -c 5 # the 5th character
$ cut -n 20 # the 20th line
$ cut -f 3 # the 3rd field (tab delimited)
$ cut -f 3 -d " " # (space delimited, e.g. words)
# tr
$ tr "()" "[]" # replace round brackets with square ones
$ tr -d "[a-z]" # delete all lower case characters
$ tr -s " " " " # strip out duplicate spacesgit
# reset a git repository
git checkout master
git reset --hard $(git commit-tree HEAD^{tree} -m "Initial commit")
git push origin master --forcefiles
# list the contents of an archive
unzip -l /path/to/file.zipyes, I have a licence
# find a BBC programme and grab the series
get_iplayer -i "Once Upon a Time in Space"
get_iplayer --get --pid=m002hyt5 --pid-recursive
# List recent iPlayer downloads
% cut -f2 -d "|" .get_iplayer/download_history | sort | uniqpdfs
# make a quick pdf from markdown using pandoc
touch tmp.md
open tmp.md
pandoc tmp.md --to pdf
quarto render tmp.md --to pdf
# merge a load of pdfs into one document
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf file3.pdf
# extract the text from a (non-scan) pdf
pandoc example.pdf -o example.md
# and from a scan/image pdf
brew install poppler
pdftotext example.pdf