Search code examples
bashfileterminalcommand-linexmgrace

How to place files containing increasing numeric names consecutively in the terminal


I have certain files named something like file_1.txt, file_2.txt, ..., file_40.txt and I want to plot them in the terminal using xmgrace like this:

xmgrace file_01.txt file_02.txt [...] file_40.txt

What would be a bash code, maybe a for loop code so that I don't have to write them one by one from 1 to 40, please?

[Edit:] I should mention that I tried to use the for loop as follows: for i in {00-40}; do xmgrace file_$i.txt; done, but it didn't help as it opens each file separately.


Solution

  • Depending of the tool you use:

    xmlgrace file_*.txt
    

    using a glob (this will treat all files matching the pattern)

    or as Jetchisel wrote in comments:

    xmlgrace file_{1..40}.txt
    

    This is brace expansion

    For general purpose, if the tool require a loop:

    for i in {1..40}; do something "$i"; done
    

    or

    for ((i=0; i<=40; i++)); do something "$i"; done