28 lines
535 B
Bash
28 lines
535 B
Bash
|
#! /bin/bash
|
||
|
|
||
|
# Do search and replace for large files
|
||
|
|
||
|
START=$(date +%s)
|
||
|
BASE=$(dirname $(dirname $(realpath -s $0)));
|
||
|
|
||
|
CORPUS_FILE="$BASE/csv/corpus.csv"
|
||
|
PAIRS_FILE="$BASE/csv/pairs.csv"
|
||
|
REPLACED_FILE="$BASE/csv/replaced.csv"
|
||
|
|
||
|
if [ -f "$REPLACED_FILE" ]; then
|
||
|
rm "$REPLACED_FILE"
|
||
|
fi
|
||
|
|
||
|
echo "Generating replaced.csv..."
|
||
|
|
||
|
cp "$CORPUS_FILE" "$REPLACED_FILE"
|
||
|
|
||
|
while IFS=, read -r KEY VAL
|
||
|
do
|
||
|
sed -i -e "s/$KEY/$VAL/g" "$REPLACED_FILE"
|
||
|
done < "$PAIRS_FILE"
|
||
|
|
||
|
END=$(date +%s)
|
||
|
SECONDS=`expr $END - $START`
|
||
|
echo "Replacement took ${SECONDS}s"
|