LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-17-2018, 08:46 AM   #1
vynilas
LQ Newbie
 
Registered: Jun 2018
Location: Nice France
Distribution: ubuntu
Posts: 4

Rep: Reputation: Disabled
sed syntax for deleting, I guess...


Hello !

one gave me a sed script file filter.sed which starts with the 3 following blocks :

Code:
/Setting env. variables.
*$/,/BUILD: .*
*$/d
/^WARNING: .* logout and login .*
*$/,/^=*
*$/d
/All Rights Reserved.
*$/,/See error log file for details.
*$/d
I run this script with : echo "hello" | sed -f filter.sed
If the sed script contains only those lines, sed call fails complaining :

sed: file p.sed line 1: unterminated address regex

If I provide the entire sed script (sed.txt attached to this message) , it works smoothly.

Googling to understand sed syntax couldn't provide me the explanation why those delete are splitted over 3 lines.

May I ask you some hints please ?

Cheers
Attached Files
File Type: txt sed.txt (5.6 KB, 18 views)

Last edited by vynilas; 12-17-2018 at 08:49 AM.
 
Old 12-17-2018, 11:33 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
the original sed contains \r, your modified version contains \n as the last char (for example in line 1, line 2 ...)
 
Old 12-18-2018, 03:14 AM   #3
vynilas
LQ Newbie
 
Registered: Jun 2018
Location: Nice France
Distribution: ubuntu
Posts: 4

Original Poster
Rep: Reputation: Disabled
Dear Pan,
Thanks for your answer.
Unfortunately, there is no relation between this issue and the carriage return point.
Indeed, I had to copy paste from a linux guest host by a windows running virtual box, hence the \n in my forum message.
Cheers
Sylvain
 
Old 12-18-2018, 03:42 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by vynilas View Post
Hello !

one gave me a sed script file filter.sed which starts with the 3 following blocks :

Code:
/Setting env. variables.
*$/,/BUILD: .*
*$/d
/^WARNING: .* logout and login .*
*$/,/^=*
*$/d
/All Rights Reserved.
*$/,/See error log file for details.
*$/d
A newline is the end of a command for sed, except if you put a backslash before it. Backslashes remove the special meaning of characters, and the newline becomes an ordinary character, not a line delimiter.

I tried it like this directly on the command line:
Code:
$ echo bla | sed '/Setting env. variables.\
*$/,/BUILD: .*\
*$/d'
bla
$ echo -e 'Setting env. variables,\n\n\n' | sed '/Setting env. variables.\
*$/,/BUILD: .*\
*$/d'

Last edited by berndbausch; 12-18-2018 at 03:46 AM.
 
1 members found this post helpful.
Old 12-18-2018, 04:31 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by vynilas View Post
Dear Pan,
Thanks for your answer.
Unfortunately, there is no relation between this issue and the carriage return point.
Indeed, I had to copy paste from a linux guest host by a windows running virtual box, hence the \n in my forum message.
Cheers
Sylvain
If there are \n at the end of the lines it prints the error message (what you got).
If I replace \n to \r it will work.
 
Old 12-18-2018, 07:24 AM   #6
vynilas
LQ Newbie
 
Registered: Jun 2018
Location: Nice France
Distribution: ubuntu
Posts: 4

Original Poster
Rep: Reputation: Disabled
@ Pan64 : Many thanks for this precision.
My mistake was to use visual code to edit the sed script file.... When I edit the sed script file with vi, I can see that the 3 first lines are actually one and only one line, each of its 3 chunks are separated by the special char ^M (CR), which is not the native linux carriage return. Furthermore, ^M is misinterpreted by sed.
Removing the ^M makes the job !

@berndbausch Thanks for the tips
 
Old 12-18-2018, 07:33 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
glad to help you. If you really want to say thanks just click on yes.
 
1 members found this post helpful.
  


Reply



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
gphoto2- basic syntax for deleting file from command line eco_bach Linux - Software 8 12-30-2016 02:16 AM
deleting duplicate lines without deleting first instance of the duplicated line jkeertir Linux - Newbie 2 02-07-2011 06:55 AM
[SOLVED] binutils configure.guess - cannot guess build type bisonapp Linux From Scratch 3 01-09-2011 03:31 AM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 11:26 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:50 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
Open Source Consulting | Domain Registration