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 |
Well i am guessing that script.txt is in the top folder as well? ie you have folders A, B and C along with script.txt
If the above assumption is correct (and I understand the question correctly): Code:
for dir in * |
This works for me:
Code:
for name in *; do |
that works! many thanks for your help!
|
Brilliant :) Could you mark the thread as 'SOLVED', then? Thanks,
|
All times are GMT -5. The time now is 05:15 AM. |