I have a text file with this pattern:
\t (hello world)
I need to replace the text in parenthesis with a unique value (e.g. ob1, obj2, etc), such that
\t (obj)
\t (obj)
\t (obj)
becomes…
\t (obj1)
\t (obj2)
\t (obj3)
Or anything else that is unique. A solution that uses any tool that works in cygwin will work. My attempt using bash and sed to do this failed:
#!/bin/bash
x=1
for fl in myfile; do
cp $fl $fl.old
sed 's/\\t \(.*\)/\\t \("${x}"\)/g' $fl.old > $fl.new
x=$((x+1))
echo $x
done
The best way I know how to do this is with a perl in-place edit:
E.g. myfile.txt contains:
Run the in-place edit:
myfile.txt now contains:
Obviously adjust
2000to your requirements.EDIT: If you wish to use incrementing identifiers use: