Coding

Various of my most frequently used scripts and one-liners for my most often required tasks. All run on my Xubuntu 20.04 and 21.04 machines, save, obviously, the Mac OS X bootcodes.

Git Wrangling

To rename a file in a git repository
git mv oldfilename.xyz newfilename.xyz
then git commit & push as per usual.

To delete a file from a git repository:
git rm filename.xyz
then git commit & push as per usual.

To delete a folder (within a folder) from a git repository:
git rm -r Folder-to-keep/Folder-to-remove/
then git commit & push as per usual.

After git add * & git commit, to clear the commit without clearing the changes:
git reset --soft HEAD~1

PDF Wrangling

To get the number of pages of a pdf:
qpdf --show-npages OriginalFile.pdf
To ‘burst’ a pdf into single page files (files will be named NewFile-1.pdf, NewFile-2.pdf, etc):
qpdf --split-pages=1 OriginalFile.pdf NewFile.pdf
To split a pdf into chunks of 300 pages (files will be named NewFile-001-300.pdf, etc.):
qpdf --split-pages=300 OriginalFile.pdf NewFile.pdf
To extract a set of consecutive pages from a pdf, keeping metadata:
qpdf input.pdf --pages . 51-100 -- output.pdf
To extract a set of consecutive pages from a pdf, removing metadata:
qpdf --empty --pages infile.pdf 51-100 -- outfile.pdf

Text File Wrangling

To remove a continuous set of numbered lines (in this example, lines 10 to 15) reiterated over a folder of text files:
sed -i '10,15d' folder/*.txt
To remove all blank lines:
sed -i '/^$/d' textfile.txt

Text Searching

Grep print following lines: -A n
Grep print preceeding lines: -B n
Grep print lines before and after: -C n
Grep suppress filename: -h
Grep case insensitive: -i
(Gnu) Grep returning only the matching text: -o

Mac OS X Boot codes

Choose boot device (e.g. USB drive): Option (‘alt’ ⌥) alone.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.