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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
03-11-2017, 05:06 PM
|
#16
|
LQ Veteran
Registered: May 2008
Posts: 7,000
|
Quote:
Originally Posted by rknichols
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.
|
|
|
03-11-2017, 05:25 PM
|
#17
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,789
|
Quote:
Originally Posted by GazL
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
|
|
|
03-11-2017, 06:06 PM
|
#18
|
LQ Veteran
Registered: May 2008
Posts: 7,000
|
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.
|
03-12-2017, 01:02 AM
|
#19
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240
Original Poster
Rep:
|
Quote:
Originally Posted by GazL
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
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!
|
|
|
03-12-2017, 01:54 AM
|
#20
|
Senior Member
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240
Original Poster
Rep:
|
Quote:
Originally Posted by GazL
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.
|
|
|
03-12-2017, 04:05 AM
|
#21
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,628
|
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.
|
|
|
All times are GMT -5. The time now is 07:50 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|