LinuxQuestions.org
Review your favorite Linux distribution.
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 03-11-2017, 05:06 PM   #16
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,000

Rep: Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133

Quote:
Originally Posted by rknichols View Post
The magic incantation to prevent that when not using [CODE] ... [/CODE] tags is "[NOPARSE] ... [/NOPARSE]".
Ahh, thanks for that. I tried [pre]...[/pre] but that didn't work. I'll have to try and remember those.

BTW, even in code tags it didn't work:
Code:
[*]one[*]two[*]three
(should be on separate lines.)

Last edited by GazL; 03-11-2017 at 05:08 PM.
 
Old 03-11-2017, 05:25 PM   #17
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,789

Rep: Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217
Quote:
Originally Posted by GazL View Post
BTW, even in code tags it didn't work:
Code:
[*]one[*]two[*]three
(should be on separate lines.)
Weird! Perhaps the parser is trying to interpret the "[*]" as part of a nonexistent list construct. If you double-space that input, it displays as single-spaced lines.
Code:
[*]one
[*]two
[*]three
 
Old 03-11-2017, 06:06 PM   #18
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,000

Rep: Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133Reputation: 5133
BTW, watch out for the 'N' option in sed. If it hits an end of file it'll terminate the script prematurely. Here I've added an extra line of input 'seven'.

Code:
test@ws1:/tmp$ sed -e 'N;s/\n*/(*)/' /tmp/sed.in 
(*)one
two
(*)three
four
(*)five
six
seven
As you can see, the script terminates prematurely before doing the s/// on the final line when it tries to append(N) the non-existent line 8.
 
1 members found this post helpful.
Old 03-12-2017, 01:02 AM   #19
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by GazL View Post
It now gets to the end of the script and does an implicit print of the buffer. It prints '(*)one\ntwo' to the terminal, which displays as
Code:
(*)one
two
I suspect part of your confusion is stemming from the fact you are confusing the meaning of '*' in a regex, with the meaning of '*' in a shell glob. They are quite different.
I hope that clears it up for you.
Really nice explanation. This makes it perfectly clear. I wasn't confused by * actually, I simply didn't understand how sed interpreted it and the 'trick' (which now seems perfectly logical) with the \n line. Now it's clear that the \n remains there where it should be (as it's not matched). I kept thinking there was a \n at the beginning of the first, third, etc. lines (because that's where it matched the string, but concomitantly I knew that \n* could match no \n at all, as rknichols had already explained) - which didn't make sense, yes I think I'm really starting to finally understand N. Thank you!
 
Old 03-12-2017, 01:54 AM   #20
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by GazL View Post
BTW, watch out for the 'N' option in sed. If it hits an end of file it'll terminate the script prematurely. Here I've added an extra line of input 'seven'.
As you can see, the script terminates prematurely before doing the s/// on the final line when it tries to append(N) the non-existent line 8.
So basically the newline isn't matched (as there's no additional line) and that's why there's nothing to substitute and it ignored the last line, if my understanding is correct.

P.S. By the way, I used square brackets within codes by pressing an addition 'enter' where I knew the line would split and it works like that, even if it's not so practical with a long quoted text.

Last edited by vincix; 03-12-2017 at 01:56 AM.
 
Old 03-12-2017, 04:05 AM   #21
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,628

Rep: Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524Reputation: 7524
on the last line N could not be executed. As you stated before already \n* matches anyway (including the empty string), so the real reason is: sed stopped at the command N (because it failed) and did not try to substitute any more.
 
  


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
create file list: SED inline vs SED standalone, enormous speed difference Corsari Linux - Newbie 4 09-02-2013 03:01 AM
[SOLVED] Multipal line edited using sed, how to make sed specific coolpraz Programming 4 01-05-2013 01:14 PM
[Cygwin, sed] Using filenames as both files and search strings within sed lingh Linux - Newbie 5 10-20-2012 10:38 AM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07: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