0

I have 15 pair of array files for which I need to perform certain operation (say subtraction).
My file names are:

pr1_A.txt
evs1_A.txt
pr2_A.txt
evs2_A.txt
...
pr15_A.txt
evs15_A.txt

I want to perform:

pr1_A - evs1_A
pr2_A - evs2_A
...
pr15_A - evs15_A

Can anybody guide me how to do it using a for loop.

4
  • @genisage undelete your answer please, we'll fix it. I think the problem was in the question more tha in your answer. Commented Jan 19, 2015 at 4:31
  • please add to your question the information you had provided to genisage Commented Jan 19, 2015 at 4:32
  • In my case, r is variable in the file name, x1 = evs_Amon_r1i1p1.txt, y1 = pr_Amon_r1i1p1.txt, x2 = evs_Amon_r2i1p1.txt, y2 = pr_Amon_r2i1p1.txt, x3=evs_Amon_r1i1p2.txt, y3 = pr_Amon_r1i1p2.txt ....etc. Variable is r part of the file name in the middle, which is common for both evs and pr files. Commented Jan 19, 2015 at 20:13
  • ok @user962808. genisage's answer may help you. Doesn't it? Commented Jan 19, 2015 at 20:21

1 Answer 1

1
for n in evs_Amon*
do
  tmp=${n:3}
  x='pr'$tmp
  y='evs'$tmp
  #do stuff using x and y
done

Is that what you're looking for?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this my n is string actually it is x = pr_Amon_CCSM4_r1i1p1.txt; y = evs_Amon_CCSM4_r1i1p1.txt, then for n =2, x = pr_Amon_CCSM4_r1i1p2.txt; y = evs_Amon_CCSM4_r1i1p2.txt ... for n = 10 x = pr_Amon_CCSM4_r2i1p1.txt; y = evs_Amon_CCSM4_r2i1p1.txt whereas for n = 12, x = pr_Amon_CCSM4_r1i1p6.txt; y = evs_Amon_CCSM4_r1i1p6.txt. How to declair string n in this case ?
Excelent! +1 for that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.