I have two files: a.patterns contains patterns in a one per line way
"`"
"^"
"<"
"<("
"<)"
"<["
"="
">"
"_;|^+*+?@"
and b.data contains comma separated values.
1,1,0,"*",1
2,1,1,"*",1
3,0,0,"<)",0
The purpose is to substitute take each pattern matched in the csv file with that pattern's index (i.e., its line number).
The problem is that I load each pattern into a variable, and use sed to evaluate/replace it but frequently the patterns contain special characters.
...
while read line;
do
counter=`expr $counter + 1`
temp=`echo "$temp" | sed "s/$line/$counter/"`
done < a.patterns
...
My question: is there a way to tell sed to count the contents of the variable as literals? Ideally I would like to avoid inserting escape character for all special characters in the pattern file or alternative ways to achieve the same?
Thank you.
a.patterns
will cause problems withsed
. – Hauke Laging Dec 17 '14 at 23:10