0

Using the Xgraph data plotting tool (XGRAPH), I want to plot a bunch of files named test1.csv test2.csv, ...

The command would be

xgraph -columns 1 2 test1.csv -columns 1 2 test2.csv

and so on· Is there any way I can use brace expansion or some other magic to circumvent manually typing the pattern -columns 1 2 file.csv again and again?

reloh100
  • 65
  • 1
  • 8

2 Answers2

3

I think this function should work for you...

graph-build() {
  # loop through commandline filenames and join together
  for file in "${@}"; do
    cmd_build+=(-columns 1 2 "${file}")
  done
  # run xgraph
  xgraph "${cmd_build[@]}"
}

# Run with the expansion as required.
graph-build file{1..3}.csv

Edit: Syntax updated due to helpful comments highlighting the whitespace issue with filenames in my initial revisions.

J.Peace
  • 71
  • 4
1

With the specific set of filenames given in the question you can use brace expansion and eval to replace

xgraph -columns 1 2 test1.csv -columns 1 2 test2.csv ... -columns 1 2 test10.csv

with

eval xgraph ' -columns 1 2 test'{1..10}'.csv'
pjh
  • 6,388
  • 2
  • 16
  • 17