Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

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

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.

share|improve this answer

Your Answer

 
discard

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.