Hi guys
Let me at first describe the whole thing that I'm trying to do. Lets say I have 100 files like the following one.
Ow 1230 16.000000 -0.834000 16.083957
1.751652398 -17.20094528 -4.450623277
Hw 1231 1.000000 0.417000 14.341378
2.128451025 -16.83399008 -5.250372494
Hw 1232 1.000000 0.417000 16.844104
0.9093140466 -16.75614395 -4.356548788
Ow 1233 16.000000 -0.834000 20.225603
-2.889503614 -23.61890070 10.03599967
Hw 1234 1.000000 0.417000 20.855176
-2.102487366 -23.08165809 10.12659865
Hw 1235 1.000000 0.417000 20.448925
-2.604411345 24.18827587 10.26811687
Ow 1236 16.000000 -0.834000 9.718498
-18.13116183 15.29853776 -10.10585481
Hw 1237 1.000000 0.417000 9.855829
-18.86525637 14.71715826 -10.30418717
Hw 1238 1.000000 0.417000 9.294911
-17.66286350 15.38507405 -10.93618054
Ow 1239 16.000000 -0.834000 10.477756
11.91804137 -21.91087964 -11.56566494
I want to merge all the 100 files. The second field of the 1st,3rd..so on lines shows the atom number i.e 1230,1231. All the files are numbered from 1230..1239. So for the 1st file this numbers are ok, for the second file numbering should start from 1240,1241..and this should go on all the way through the last file. I did merge the files through a loop, The way I was trying to get those atom numbers in an array, replace those array elements with a counter. My thinking was this-
myarr=($(awk 'NR % 2 ==1' TestMe | awk '{print $2}'))
echo ${myarr[@]}
counter=1230;
for i in "${myarr[@]}"
do sed "s/$i/$j/g" TestMe;
counter=$(($counter+1));
done
I just don't know how to replace array elements in a sed command. Or is it the right way to loop through array elements. And whenever I tried to use that piece of code it said-
-bash: syntax error near unexpected token `counter=$(($counter+1))'
Thanks a lot!
For 5 files,the output looks like this-