linux pattern match program input -


i have multiple files same pattern: file1.txt, file2.txt, file3.txt, etc. want run java program each file, this:

java main file[0-9]*.txt 

but doesn't work. possible want terminal? if not, change program read multiple args, again, i'd need type 100+ files manually.

as written, command

java main file[0-9]*.txt 

would pass of matching filenames file1.txt, file2.txt, etc., in 1 command. op requested "run java program each file", implies series of commands intended. (in bash or posix shell), 1 this:

for file in file[0-9]*.txt; [ -f "$file" ] && java main "$file"; done 

breaking down:

  • this makes loop for file in file[0-9]*.txt using suggested pattern,
  • it checks ensure loop variable file has found file rather wildcard expression found none,
  • runs java class main each corresponding file.

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -