Originally Posted by conrog66
I am trying to remove blank lines from a txt.file. I have googled a potential solution which is using- sed -e /^$/d my_data.txt.
This command works when I just enter it within the terminal on raspberry pi; however, when I run my script with this command I get a syntax error. The error is as follows:
pi@raspberrypi ~ $ sudo python my_data_analysis_script.py
File "my_data_analysis_script.py", line 19
sed -e /^$/d my_data.txt
SyntaxError: invalid syntax
Note- I get the syntax error whether I run the code with or without ' ' around the /^$/d
Are you aware that Python is not a shell command interpreter?
If you want to execute the sed command in a script, it has to be a shell script, not a Python script.
Or, in Python, use the system