Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

To move some data from a program on Windows to the same program on Mac, the program has a built in backup tool. Unfortunately it seems they never tested cross platform compatibility as the ZIP file that it produces has filenames as:

Data\Shared\filename.extension
Data\Users\Ashley\filename.extension
etc etc

So, I need to convert these backslash extensions to their folder equivalent. There aren't so many differences so I am happy to do a mv command on them and then strip the beginning "folder" - but that's where I'm stuck.

Suggestions on how to remove (for example) the Data\Shared or do it quickly by moving based on the filename would be great. Thanks

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Something like this should get you going change BASE to be whatever base path you want.

#!/bin/bash
BASE="/tmp"
for file in *
do
    nf=$(echo "$file" | sed 's|\\|/|g')
    filename=$(basename "$nf")
    path=$(dirname "$nf")
    mkdir -p "$BASE/$path"
    cp "$file" "$BASE/$path/$filename"
done

I knocked this up on a Linux system but I expect it will work as expected on OSX.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.