Last active
April 29, 2022 18:56
-
-
Save mvogelgesang/3c469cac7fa4ec8c193cf30a770129a9 to your computer and use it in GitHub Desktop.
Given an input file containing a newID value and oldId value, perform a mass find/replace across a series of files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set -x | |
# CSV FILE MUST HAVE EMPTY LINE AT END AND NO "" | |
# Given an input file containing a newID value and oldId value, perform a mass find/replace across a series of files | |
INPUT=inputdata.csv | |
EXCLUDEDIR=/Users/mv/folder\ to\ exclude | |
EXCLUDEFILE=fileToExclude.csv | |
SEARCHDIR=/Users/mv/search\ directory | |
OLDIFS=$IFS | |
IFS=',' | |
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } | |
while read newId oldId | |
do | |
#echo "newId: $newId" | |
#echo "oldId: $oldId" | |
grep -RIlZ --exclude-dir="$EXCLUDEDIR" --exclude "$EXCLUDEFILE" "$oldId" "$SEARCHDIR" | while read -r line ; do | |
#echo "$line" | |
sed -i "" "s/$oldId/$newId/g" """$line""" | |
done | |
done < $INPUT | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment