Question: I have a file `pattern.txt`:

```
pattern1
pattern2
pattern3
pattern4
...

```

and I have another file called `text.txt` and it contains a huge random string with spaces, newlines, etc.

I want to process the content of those two files to be able to make these calls (the order of `-p` and `-t` doesn't matter):

```
python3 main.py -p pattern1 -t 'text.text content'
python3 main.py -p pattern2 -t 'text.text content'
python3 main.py -p pattern3 -t 'text.text content'
... etc

```

This is what I've done so far:

```
cat patterns.txt | xargs -i -n1 python main.py -p {} -t "how are you doing"

```

Answer: 
Use `xargs -a` to execute `main.py` once for each line in `pattern.txt`.

```
xargs -a pattern.txt -I {} python3 main.py -p {} -t "$(< text.txt)"

```

You can also use `-P` to run multiple copies of the script in parallel.

If `main.py` is executable and has a shebang line such as `#!/usr/bin/env python3` then it's best to leave out the explicit `python3` call. Let scripts control their own interpreters:

```
xargs -a pattern.txt -I {} ./main.py -p {} -t "$(< text.txt)"

```

You could also do this with a hand-rolled loop if you prefer.

```
text=$(< text.txt)
while IFS= read -r pattern; do
    ./main.py -p "$pattern" -t "$text"
done < pattern.txt

```
You could loop each line through the pattern.txt:

```
while read line; do python3 main.py -p "$line" -t 'text.text content'; done < pattern.txt

```