0

I have 2 or more jsonl files files and my objective is to merge the files and shuffle the lines of the output. The easy case is where I know the number of files and the file names and I can use the command below

cat file1.txt file2.txt file3.txt | shuf

However I don't know the number of files in advance. Is there a way so that a script merge.sh will work on variable number of arguments

merge.sh file1.txt file2.txt 
merge.sh file1.txt file2.txt file3.txt file4.txt 

Basically I don't know how to use $1 etc when the number of arguments is variable

RF1991
  • 2,037
  • 4
  • 8
  • 17
vkaul11
  • 4,098
  • 12
  • 47
  • 79
  • 2
    You use `"$@"` (with the quotes) to work with "all the parameters", no matter now many there are: `cat "$@" | shuf` – glenn jackman Jul 17 '23 at 20:02
  • BTW, don't put `.sh` extensions on scripts; extensions belong on shell _libraries_, not executable commands. (That said, to create a proper executable command, you'll want a shebang on the first line -- like `#!/usr/bin/env bash` -- and executable permissions). It's the same as how Python libraries end with `.py`, but Python scripts in `/bin` don't (you run `pip`, not `pip.py`). – Charles Duffy Jul 17 '23 at 20:19

0 Answers0