{"id":2005,"date":"2020-11-07T14:56:25","date_gmt":"2020-11-07T14:56:25","guid":{"rendered":"https:\/\/anterotesis.com\/wordpress\/?page_id=2005"},"modified":"2026-07-22T11:14:14","modified_gmt":"2026-07-22T10:14:14","slug":"coding","status":"publish","type":"page","link":"https:\/\/anterotesis.com\/wordpress\/coding\/","title":{"rendered":"Coding"},"content":{"rendered":"<p>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.<\/p>\n<h2>Git Wrangling<\/h2>\n<p>To rename a file in a git repository<br \/>\n<code>git mv oldfilename.xyz newfilename.xyz<\/code><br \/>\nthen git commit &amp; push as per usual.<\/p>\n<p>To delete a file from a git repository:<br \/>\n<code>git rm filename.xyz<\/code><br \/>\nthen git commit &amp; push as per usual.<\/p>\n<p>To delete a folder (within a folder) from a git repository:<br \/>\n<code>git rm -r  Folder-to-keep\/Folder-to-remove\/<\/code><br \/>\nthen git commit &amp; push as per usual.<\/p>\n<p>After git add * &amp; git commit, to clear the commit without clearing the changes:<br \/>\n<code>git reset --soft HEAD~1<\/code><\/p>\n<h2>PDF Wrangling<\/h2>\n<p>To get the number of pages of a pdf:<br \/>\n<code>qpdf --show-npages OriginalFile.pdf<\/code><br \/>\nTo &#8216;burst&#8217; a pdf into single page files (files will be named NewFile-1.pdf, NewFile-2.pdf, etc):<br \/>\n<code>qpdf --split-pages=1 OriginalFile.pdf NewFile.pdf<\/code><br \/>\nTo split a pdf into chunks of 300 pages (files will be named NewFile-001-300.pdf, etc.):<br \/>\n<code>qpdf --split-pages=300 OriginalFile.pdf NewFile.pdf<\/code><br \/>\nTo extract a set of consecutive pages from a pdf, keeping metadata:<br \/>\n<code>qpdf input.pdf --pages . 51-100 -- output.pdf<\/code><br \/>\nTo extract a set of consecutive pages from a pdf, removing metadata:<br \/>\n<code>qpdf --empty --pages infile.pdf 51-100 -- outfile.pdf<\/code><\/p>\n<h2>Text File Wrangling<\/h2>\n<p>To remove a continuous set of numbered lines (in this example, lines 10 to 15) reiterated over a folder of text files:<br \/>\n<code>sed -i '10,15d' folder\/*.txt<\/code><br \/>\nTo remove all blank lines:<br \/>\n<code>sed -i '\/^$\/d' textfile.txt<\/code><\/p>\n<h2>Text Searching<\/h2>\n<p>Grep print following lines: -A n<br \/>\nGrep print preceeding lines: -B n<br \/>\nGrep print lines before and after: -C n<br \/>\nGrep suppress filename: -h<br \/>\nGrep case insensitive: -i<br \/>\n(Gnu) Grep returning only the matching text: -o<br \/>\n(Gnu) Grep search to first occurrence of final character: -oP &#8216;A.+?B&#8217;<br \/>\n&#8211; Useful for extracting tags from html and xml files: grep -oP &#8216;&lt;.+?&gt;&#8217; file.html<\/p>\n<h2>Mac OS X Boot codes<\/h2>\n<p>Choose boot device (e.g. USB drive): Option (&#8216;alt&#8217; \u2325) alone.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/anterotesis.com\/wordpress\/coding\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":9,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-2005","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/pages\/2005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2005"}],"version-history":[{"count":17,"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/pages\/2005\/revisions"}],"predecessor-version":[{"id":2672,"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/pages\/2005\/revisions\/2672"}],"wp:attachment":[{"href":"https:\/\/anterotesis.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}