Hi all.
I'm in the unfortunate position that I have to work with Windows and Linux systems using MATLAB. For my MATLAB program I have config-files that contain the pathes to the corresponding data, etc. Now to switch from Windows to Linux and back, I'm trying to write a script that replaces the paths for the datasets. It is supposed to this recursivley for all configs contained in the 'data_analysis' directory.
Now it does work replacing simple strings (i.e.: for a simple variable), but with Windows- and Linux-paths it doesn't which has to do with the '\', ':', etc.
I call the script in the following form:
>> replace_string.sh C:\data_analysis /media/eclipse_ti/data_analysis/ /media/eclipse_ti/data_analysis/
where the 1. argument is the string to replace, 2. the string that will be put, 3. where to replace it.
I hope somebody can help me out and perhaps help me create a script that's as robust as possible.
Thanks in advance,
Mike
Code:
#!/bin/bash
directory=$3
includedFiles=$4
stringToReplace=$1
replacementString=$2
currentDate=`(date +%Y%m%d)`
echo $directory
echo $#
echo $stringToReplace
#echo $replacementString
if [ $# -eq 4 ]
then
fileList=`grep --include=$includedFiles -RHl $stringToReplace $directory`
# echo "grep --include=$includedFiles -RHl $stringToReplace $directory"
fi
if [ $# -eq 3 ]
then
fileList=`grep -RHl $stringToReplace $directory`
# echo "grep -RHl $stringToReplace $directory"
fi
for file in $fileList
do
echo "Processing $file"
sed --in-place="_StringReplacementBKP$currentDate" "s|$stringToReplace|$replacementString|g" $file
done