shell script for substitution
Dear all,
I am struggling with a substitution in multiple files by using shell scripting and I would appreciate if anyone could help.
So, I have 100 folders each of them include a file called script.txt and script2.txt. the file script.txt has and 100include files that have the same name like the folders. So, for example if I have the folders
A, B and C
then the script.txt will include 3lines such as:
*include A
*include B
*include C
I want for each folder (A, B and C) to create script2.txt which will substitute *include A with $include A, respectively for each folder.
so for folder A, I will have script2.txt
$include A
*include B
*include C
for B:
*include A
$include B
*include C
I tried the followed script:
#!/bin/bash
for name in *
do
find . -iname '*_' |sed 's/^..//' | while read line;
do
if [ "$line" != "$name" ]
then
perl -pe 's/\*include $line/\$include $line/' $name/HyperDM.gms > $name/HyperDM_scen0.gms
fi
done
done
but it is substituting "*" with "$" in each file for all the lines. could someone help me? I think i should probably close earlier a loop, but I am totally confused and cannot solve it.
thanks, chrysanthi
|