LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2015, 02:06 PM   #1
conrog66
LQ Newbie
 
Registered: Nov 2015
Posts: 5

Rep: Reputation: Disabled
Question sed command


Hello,

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
 
Old 11-18-2015, 02:26 PM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,158
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Quote:
Originally Posted by conrog66 View Post
I have googled a potential solution which is using- sed -e /^$/d my_data.txt.
You have done no such thing.
That takes some balls to claim that.

I gave you that snippet in http://www.linuxquestions.org/questi...2/#post5451508

Why the near duplicate thread?

Show us the contents of my_data_analysis_script.py

Last edited by Habitual; 11-18-2015 at 02:28 PM.
 
Old 11-18-2015, 02:52 PM   #3
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,158
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
python has an RE module you can import.
https://docs.python.org/2/library/re.html

Good Luck.

Last edited by Habitual; 11-18-2015 at 02:54 PM.
 
Old 11-19-2015, 07:44 PM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
Originally Posted by conrog66 View Post
Hello,

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 call.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed substitution gives error "sed: command garbled" gsai0205 Linux - Newbie 3 09-13-2013 10:01 AM
[SOLVED] sed gives :sed: -e expression #1, char 1: unknown command: `'' samasat Linux - Newbie 10 06-09-2012 06:31 PM
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 01:27 PM
Sed command - command garbled errror gauavmahesh Linux - Newbie 3 03-30-2012 11:04 PM
Modifying text file with "one command line" SED command... daleo Linux - Newbie 3 01-13-2012 06:32 AM


All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration