0

I have lines of codes all of which look similar. Giving some examples below

gmx trjconv -s md_0_10.tpr -f md_0_10.xtc -o md_0_10_center.xtc -center -pbc mol -ur compact
gmx trjconv -s md_0_10.tpr -f md_0_10_center.xtc -o start.pdb -dump 0
gmx trjconv -s md_0_10.tpr -f md_0_10_center.xtc -o md_0_10_fit.xtc -fit rot+trans
gmx trjconv -s md_0_11.tpr -f md_0_11.xtc -o md_0_11_center.xtc -center -pbc mol -ur compact
gmx trjconv -s md_0_11.tpr -f md_0_11_center.xtc -o start.pdb -dump 0
gmx trjconv -s md_0_11.tpr -f md_0_11_center.xtc -o md_0_11_fit.xtc -fit rot+trans
gmx trjconv -s md_0_12.tpr -f md_0_12.xtc -o md_0_12_center.xtc -center -pbc mol -ur compact
gmx trjconv -s md_0_12.tpr -f md_0_12_center.xtc -o start.pdb -dump 0
gmx trjconv -s md_0_12.tpr -f md_0_12_center.xtc -o md_0_12_fit.xtc -fit rot+trans

So essentially using Control + R just narrows down to this bunch of similar lines. But essentially I will have to evade through these bunch of similar lines to narrow down to the final one. I was thinking of some tricks.

echo 10step1 | gmx trjconv -s md_0_10.tpr -f md_0_10.xtc -o md_0_10_center.xtc -center -pbc mol -ur compact
echo 10step2 | gmx trjconv -s md_0_10.tpr -f md_0_10_center.xtc -o start.pdb -dump 0
echo 10step3 | gmx trjconv -s md_0_10.tpr -f md_0_10_center.xtc -o md_0_10_fit.xtc -fit rot+trans
echo 11step1 | gmx trjconv -s md_0_11.tpr -f md_0_11.xtc -o md_0_11_center.xtc -center -pbc mol -ur compact
echo 11step2 | gmx trjconv -s md_0_11.tpr -f md_0_11_center.xtc -o start.pdb -dump 0
echo 11step3 | gmx trjconv -s md_0_11.tpr -f md_0_11_center.xtc -o md_0_11_fit.xtc -fit rot+trans
echo 12step1 | gmx trjconv -s md_0_12.tpr -f md_0_12.xtc -o md_0_12_center.xtc -center -pbc mol -ur compact
echo 12step2 | gmx trjconv -s md_0_12.tpr -f md_0_12_center.xtc -o start.pdb -dump 0
echo 12step3 | gmx trjconv -s md_0_12.tpr -f md_0_12_center.xtc -o md_0_12_fit.xtc -fit rot+trans

After running these codes once. For re-running the code again, I use Control + R reverse search and then I put the string 10step1 or 12 step3

I wish to ask if there are other tricks which can make this process more efficient during searching and narrowing down of the required line quickly

I went through similar history search related questions in other post but they are in general and does not deal with the problem of navigating through similar lines of code.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Praveen Kumar-M
  • 592
  • 5
  • 15

2 Answers2

0

Realine prompt is capable of forward search

Alternativaly you can define a search function in your .bashrc something like

function r {
   history | grep "$*" | head -5
}
Emmanuel
  • 4,187
-2

I have setup my inputrc (can also be defined for just .bashrc) so that up and down arrows search history instead of just showing next or previous history. In this way, the up/down arrow commands behave like default on FreeBSD.

This is the inputrc snippet:

# mappings for Up/Down arrow to search through history
"\e[A": history-search-backward
"\e[B": history-search-forward

What this does exactly is, that if you type the following at the prompt:

echo 11

And then press arrow up, it will cycle through the history for those commands starting with "echo 11".

For me, this is much more intuitive, and it gives you the possibility to type in the start of your command, and cycle history for only that narrow selection.

If you combine with easy keys to cut away to the end of line, or cut one word at a time, you can get some very powerful search/browse options using up/down arrow history.

Hope this helps!