Skip to content Skip to sidebar Skip to footer

Text File Each Line To Command In Bash

okay so I have a pythonscript that takes an argument like so & ./myscript.py argumentishere what u want to do is read a text file that has multipule lines of text and for eac

Solution 1:

While you can achieve this with a bash script, probably the easier way is to use the xargs utility.

xargs -L 1 ./myscript.py <inputfile

The bash way would be:

whileread line
do
    ./myscript $linedone <inputfile

Solution 2:

#!/bin/bashcat input | whileread line
do
    ./myscript.py $linedone

you also need add #!/usr/bin/env python in the head of myscript.py and chmod executable properity to myscript.py

Solution 3:

If I were you, I'd modify the python script to take a filename as argument and do what I want with each line.

import sys
file = open(sys.argv[1])
for line in file:
    #do your thing here

Solution 4:

Have you tried this?

while IFS= read -r line; do
    ./myscript.py "$line"done < file

Post a Comment for "Text File Each Line To Command In Bash"