sptr.net
    • about sptr.net
    • about me
  • Stories
    • NixImagery
    • Poetry
    • Tales of the Family
  • Pictures
    • NixImagery on 500px
    • Wild Aye Photography
  • Tech
    • I was in the REME, I’ll have you know
    • Technical blog
  • Research
    • About my research
    • ORCID profile
    • Digital Education profile
    • The BBC’s Something Understood

    • PhD/Supervisors (login required)
    • Thesis (in work, login required)
    • Participants (login required)

On this page

  • text manipulation
  • git
  • files
  • yes, I have a licence
  • pdfs

Quick codes

A little bucket of one-liners to do clever things in the terminal
Published

7th November 2025

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 spaces

git

# reset a git repository
git checkout master
git reset --hard $(git commit-tree HEAD^{tree} -m "Initial commit")
git push origin master --force

files

# list the contents of an archive
unzip -l /path/to/file.zip

yes, 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 | uniq

pdfs

# 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
  • the NixImagery Post

  • © Copyright Nick Hood