Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

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

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.