1

So, say, I want to create a bunch of files named this way (where I have an original file "albedo10solar100" with text inside), where I vary albedo from 10 to 60 in steps of 10 and solar from 90 to 100 in steps of 5:

  • albedo10solar100.m
  • albedo10solar95.m
  • albedo10solar90.m
  • ...
  • albedo20solar100.m
  • albedo30solar100.m

I would imagine that I would have to first use the cat command numerous times first on albedo10solar100, so I would first need some shell script that could cat albedo10solar100 > albedo{$m}solar{$n}.

But then, what if I then wanted to batch replace every instance of 100 with 95 in the body of albedo10solar100? And so on for each additional file?

2 Answers 2

3

whole script will look like for creation and replacing numbers in body:

for i in $(seq 10 10 60)
do
    for j in 90 95 100
    do
        sed "s/100/$j/g" albedo10solar100.m_orig > "albedo${i}solar${j}.m"
    done
done

you need to create albedo10solar100.m_orig before, cause in case you'll use albedo10solar100.m it will be rewrited with empty file.

1

you can use sed.

sed 's/100/95/g' albedo10solar100.m > albedo10solar95.m

Of course you could substitute "100" and/or "95" with another REGEX for better pattern matching

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .