Skip to content

Instantly share code, notes, and snippets.

@ernstki
Created December 15, 2017 04:59
Show Gist options
  • Save ernstki/10c139ee05dd189cba8663638af67bc3 to your computer and use it in GitHub Desktop.
Save ernstki/10c139ee05dd189cba8663638af67bc3 to your computer and use it in GitHub Desktop.
reslashify - a sed script to reverse slashes in pathnames (DOS <--> Unix)
#!/usr/bin/env sed -f
# replace all forward slashes only if there are no backslashes
# (i.e., convert Unix-style pathnames to DOS/Windows-style ones)
/\\/! s_/_\\_g
# branch (to the end) if any substitutions have been made at this point,
# to prevent the next pattern from undoing what the first one did
t
# replace all backslashes only if there are no forward slashes
# (i.e., convert DOS-style pathnames to Unix-style ones)
/\//! s_\\_/_g
# vim: ft=sed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment