0

This is my whole script

#!/bin/bash
num_autocorellation=1
index_min=1
index_max=5000
for first in {1..10000..100}
do
for index in {$index_min..$index_max} 
do
    awk 'NR==FNR{a[$0]++;next}a[$0]-->0' eq3_900_915_dgdg_$first.ndx eq3_900_915_dgdg_$index.ndx | tee eq4_${num_autocorellation}_900_915_dgdg_$index.ndx
done
index_min=$(($index_min+100))
index_max=$(($index_max+100))
num_autocorellation=$(($num_autocorellation+1))
done

I want to have in the beginning in my nested loop something like that

for index in {1..5000} 
do
    awk 'NR==FNR{a[$0]++;next}a[$0]-->0' eq3_900_915_dgdg_1.ndx eq3_900_915_dgdg_$index.ndx | tee eq4_1_900_915_dgdg_$index.ndx
done

Then after this for loop will end I want to have

for index in {100..5100} 
do
    awk 'NR==FNR{a[$0]++;next}a[$0]-->0' eq3_900_915_dgdg_1.ndx eq3_900_915_dgdg_$index.ndx | tee eq4_2_900_915_dgdg_$index.ndx
done

and again again until 10000 in that loop

for first in {1..10000..100}

But I have a problem in this part

for index in {$index_min..$index_max} 

Instead of integer I have in the file something like that

eq4_1_900_905_dgdg_{1..5000}.ndx

but I want to have

eq4_1_900_905_dgdg_1.ndx

So how to put here

for index in {$index_min..$index_max} 

int variables?

14
  • 1
    If you are comparing line by line, use something like "comm" Commented Feb 17, 2021 at 16:17
  • 1
    Using -i inplace is never necessary. Both of my answers mentioned in my previous comment showed you how to create a new file for each input file and stackoverflow.com/questions/66141434/… specifically does what you want to do here - generate eq4foo files from eq3foo files while also displaying the output to stdout. Commented Feb 18, 2021 at 13:26
  • 1
    print > out in that script is writing the output to a file whose name is stored in the variable out that is set earlier in the script to the input file name but with 3 changed to 4 (see out = FILENAME; sub(/3/,"4",out)). The other print above it is to mimic tee. Commented Feb 18, 2021 at 14:03
  • 1
    By the way, I notice in all of your scripts you use cmd infile | tee outfile - is that because you truly do want to get the output to display on stdout as well as be written to outfile or is it just that that's the only way you know to write the output to outfile? If you don't want the output to go to stdout too you then you'd just do cmd infile > outfile Commented Feb 18, 2021 at 14:06
  • 1
    OK, that's what I suspected. So then you don't need the 2nd print on it's own in my script, just print > out. Commented Feb 18, 2021 at 14:11

0

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.