-1

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.

  • 2
    `xmgrace file_{1..40}.txt` see: [BraceExpansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) – Jetchisel Nov 27 '22 at 18:37
  • please update the question with the `for loop` code you attempted along with an explanation of what you mean by *`it didn't help me`* – markp-fuso Nov 27 '22 at 18:49
  • We encourage questioners to **show** what they have tried so far to solve the problem themselves. – Cyrus Nov 27 '22 at 19:42

1 Answers1

1

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
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • 1
    `xmlgrace file_*.txt` will also expand to `file_41.txt` (when it exists) and shows `file_10.txt` before `file_2.txt`. You might want `xmlgrace file_[1-9].txt file_[1-3][0-9].txt file_40.txt`. The brace expansion is fine. – Walter A Nov 27 '22 at 20:10