#!/bin/sh
l=92 #Space group number of datasets inculed in scaling
n=10 #this is the number of images per scan

###########DO NOT CHANGE BELOW THIS LINE##########
j=1
while ((j<=$n))
do
grep -r --include \CORRECT_$j.LP "SPACE_GROUP_NUMBER=...*$l" >>temp1.txt
sed -r -e 's/^.{0}/&'INPUT_FILE='/' <temp1.txt >temp2.txt
cat temp2.txt >> temp3.txt
echo "FRIEDEL'S_LAW= TRUE
MERGE= FALSE
MINIMUM_I/SIGMA=0"  >> temp3.txt
rm temp1.txt
rm temp2.txt
sed -i '1i\\' temp3.txt
sed '1,1s/^/OUTPUT_FILE= xscale.hkl /' temp3.txt > temp4.txt
rm temp3.txt
sed -r -e 's/CORRECT_$j.LP: SPACE_GROUP_NUMBER=   '$l'/XDS_ASCII_'$j'.HKL/' <temp4.txt >temp5.txt
sed -i '/as used in the INTEGRATE step/d' temp5.txt
sed -i '/(0: unknown symmetry and unit cell)/d' temp5.txt
awk '!a[$0]++' temp5.txt > XSCALE.INP
rm temp4.txt
rm temp5.txt
let j=j+1
done 
