# How to keep only the last group in the NDX file?

**URL:** <https://gromacs.bioexcel.eu/t/how-to-keep-only-the-last-group-in-the-ndx-file/8010>\
**Category:** User discussions\
**Created:** [January 9, 2024, 11:47am UTC](https://gromacs.bioexcel.eu/t/how-to-keep-only-the-last-group-in-the-ndx-file/8010 "2024-01-09T11:47:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Stoney](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@James\_Stoney](https://gromacs.bioexcel.eu/u/James_Stoney)\
**Post date:** [January 9, 2024, 11:47am UTC](https://gromacs.bioexcel.eu/t/how-to-keep-only-the-last-group-in-the-ndx-file/8010/1 "2024-01-09T11:47:26Z")

</div>

Using the following command I create a new group in the NDX file for the C-alpha atoms of the residues in range of 8 to 195:

gmx make\_ndx -f ref.pdb -o new.ndx \<\< EOF  
ri 8-195 & 3  
q  
EOF

Is it possible to change the number of this new group e.g. setting it to the 0 group (without explicit definition of the number of new group) ?

I found only ony possibility to add keep number\_of\_new\_group that will deleate all other groups but in this case I still need to define the number of new group.

Many thanks in advance

Cheers

---

<div class="post-metadata">

**Author:** ![milosz.wieczor](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@milosz.wieczor](https://gromacs.bioexcel.eu/u/milosz.wieczor)\
**Post date:** [January 9, 2024, 8:08pm UTC](https://gromacs.bioexcel.eu/t/how-to-keep-only-the-last-group-in-the-ndx-file/8010/2 "2024-01-09T20:08:53Z")

</div>

Not in a trivial way, numbers are assigned based on the order of entries. But you can always calculate the index of the last group in your script by counting headers:

```auto
lastindex=$[$(cat new.ndx | grep "\[" | wc -l) - 1]

```

and use $lastindex in your scripting (assuming this is where you’re going).

You can also create single-group indices with [this gromologist feature](https://gitlab.com/KomBioMol/gromologist#creating-index-groups), this way your selection will always be numbered as 0.
