LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   testing Next in sed (https://www.linuxquestions.org/questions/linux-newbie-8/testing-next-in-sed-4175601220/)

vincix 03-07-2017 05:30 AM

testing Next in sed
 
(source: http://docstore.mik.ua/orelly/unix/sedawk/ch06_01.htm)
This is the text:
Code:

Consult Section 3.1 in the Owner and Operator
Guide for a description of the tape drives
available on your system.

Code:

/Operator$/{
    N
    s/Owner and Operator\nGuide /Installation Guide\
    /
}

The substitution is self-explanatory. The problem is that when I try sed -f script file.txt, I always get an indentation for the second line, like the following:
Code:

Consult Section 3.1 in the Installation Guide
        for a description of the tape drives
available on your system.

Not sure what is causing this.

vincix 03-07-2017 06:02 AM

Yes, the problem was actually the indentation made in the script file. After deleting all of spaces before N, s and / in the script file, it worked. I thought sed was supposed to ignore that.

syg00 03-07-2017 06:13 AM

Why would you think that ?. You supplied the continuation after all ...

vincix 03-07-2017 06:40 AM

What do you mean by "you supplied the continuation"?

I thought so because some guy on a lynda course about SED said so. He pointed out that you can indent as much as you want in the script file to make the text more readable and sed will ignore the leading spaces. And of course, in the examples that he provided, including the use of Next, it worked just fine.

pan64 03-07-2017 06:48 AM

the s command (of sed) uses 3 delimiters (that is by default /):
Code:

s/substitute/replacement            /modifiers
everything between the 2nd and 3rd occurrence is the replacement string, including spaces, tabs. Those cannot be ignored.

vincix 03-07-2017 06:52 AM

Now I understand exactly where the problem was. It was the newline, obviously, and that example wasn't in the lynda course. The rest of the lines can be indented, but the \ line cannot be indented unless I want to add some spaces or whatever else after the newline. So that's exactly where the problem was.

Thanks


All times are GMT -5. The time now is 07:08 PM.