Skip to content

Instantly share code, notes, and snippets.

@steebchen
Created March 23, 2020 14:30
Show Gist options
  • Save steebchen/10fe9e8f65cf80bc30276570e1abdc0e to your computer and use it in GitHub Desktop.
Save steebchen/10fe9e8f65cf80bc30276570e1abdc0e to your computer and use it in GitHub Desktop.
Swap two files in a naming scheme of "xx-yy" where xx is a number and yy a string
#!/bin/bash
set -eu
a=$1
b=$2
mv "$a" "$a.backup"
mv "$b" "$b.backup"
numberA=$(echo $a | cut -d- -f1)
afterA=$(printf "%s" "${a#*-}")
numberB=$(echo $b | cut -d- -f1)
afterB=$(printf "%s" "${b#*-}")
mv "$a.backup" "$numberB-$afterA"
mv "$b.backup" "$numberA-$afterB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment