0

I call a python script with some command line arguments like:

python3 script.py --run 1 --filepath "this/file/dir"

I now try to parse the arguments from a config file with:

grep -v '^#' ${THIS_FILE_DIR}/model.conf | sed 's/=/ /' | xargs  -I% echo "--%"

This yields my desired string:

--run 1
--filepath this/file/dir

Is there a way to input this string dynamically into my python command, something along the lines of:

python3 script.py $(grep -v '^#' ${THIS_FILE_DIR}/model.conf | sed 's/=/ /' | xargs  -I% echo "--%")

Conf File for references

# vars
run=1
filepath=this/file/dir

1 Answer 1

0

you have multiple choices, since you already use sed, I would suggest

python3 script.py $(sed -e '/^#/d' -e 's/=/ /' -e 's/^/--/' ${THIS_FILE_DIR}/model.conf )

where

  • use -e to specify multiple sed commands
  • '/^#/d' delete lines starting with #
  • 's/^/--/' replace start of line by --
1
  • cool, I found another solution but yours is more concise!
    – user525468
    May 11, 2022 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .