0

I have a bash script which I run on my .csv file and then I run python script on the output of bash script. I would like to make everything into a single script, but bash scrip is quite complex and I couldn't find a way to use it in a Python..

grep "$(grep -E "tcp|udp" results.csv | grep -E "Critical|High|Medium" | awk -F "\"*,\"*" '{print $8}')" results.csv | sort -t',' -k4,4 -k8,8 | awk -F "\"*,\"*" '{print $5,"port",$7"/"$6,$8}' | sed '/tcp\|udp/!d' | awk '!a[$0]++' | sed '/,port,\/,/d' > out

I tried this both as a string, and as a parametrized command with subprocess, however it's just seems way too many complex characters for everything to work.

Is there a way simpler way to run this command in Python?

P.S. I know there are multiple questions & answers regarding this same topic, but none of them worked for me.

ChildinTime
  • 151
  • 1
  • 1
  • 10
  • 1
    As you see in the highlighting, your quotes are not escaped properly. –  May 18 '16 at 07:46

1 Answers1

0

Could you please escape all the " double quotes" with \ please try it out and let us know if it worked:

os.system(" grep \"$(grep -E \"tcp|udp\" results.csv | grep -E \"Critical|High|Medium\" | awk -F \"\\\"*,\\\"*\" '{print $8}')\" results.csv | sort -t',' -k4,4 -k8,8 | awk -F \"\\\"*,\\\"*\" '{print $5,\"port\",$7\"/\"$6,$8}' | sed '/tcp\|udp/!d' | awk '!a[$0]++' | sed '/,port,\/,/d' > out ")

The whole command can be put into " your_command_with\"escaped\"double quotes ". Have a nice day

Marco smdm
  • 1,020
  • 1
  • 15
  • 25