0

I am using Linux, I have a template.in file as follows:

xxxxFileNamexxxx
xxxxxxxxxFileName

I want to generate a hundred of files with the filenames and content as follows:

For R1.in

xxxx1xxxx
xxxxxxxxx1

For R2.in

xxxx2xxxx
xxxxxxxxx2

For R100.in

xxxx100xxxx
xxxxxxxxx100

I tried to use the following creatfile.csh script, but did not work. Would experts helps me out? Thanks.

set fnam=1:100

foreach fname
do cp template.in "R$fname.in"
sed FileName fname
done
Peter
  • 1
  • For future posts, you should explain what did not work. Did you not get the correct result, or did the script fail with an error message? If there is an error, you should *always* copy and paste the error message. – SethMMorton Jul 15 '13 at 22:55

1 Answers1

0

You are using bash syntax for your loop; this will fail in csh. Also, your sed command is not correct.

Try this:

foreach fname (`seq 1 100`)
    set newfile = "R$fname.in"
    cp template.in $newfile
    sed "s/Filename/$fname/" -i $newfile
end
SethMMorton
  • 45,752
  • 12
  • 65
  • 86