| Deutsch English Français Italiano |
|
<lsgokrFfuscU1@mid.individual.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feeds.phibee-telecom.net!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: John-Paul Stewart <jpstewart@personalprojects.net> Newsgroups: comp.unix.shell Subject: Re: a sed question Date: Wed, 18 Dec 2024 15:12:11 -0500 Lines: 31 Message-ID: <lsgokrFfuscU1@mid.individual.net> References: <874j304vv3.fsf@example.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net rN9iIpU/9OAfJZRaJWzgCQdc3/aQX2uge8XOkpKqsjgRA2Mjfm Cancel-Lock: sha1:wlMc+SIjygE3OSmbDgMMurJlMFw= sha256:XH6SlG7WmqMlG+QOzWe80cSTwrifAvTtr0xtT+OH7mg= User-Agent: Mozilla Thunderbird Content-Language: en-CA In-Reply-To: <874j304vv3.fsf@example.com> Bytes: 2300 On 2024-12-18 2:46 p.m., Salvador Mirzo wrote: > (*) Summary > > I wrote a sed script that makes a line replacement after it finds the > right spot. So far so good. Then I added quit command after the > change, but the quit does not seem to take effect---violating my > expectation. I'll appreciate any help on understanding what's going on. [snip] > So far so good. I decided to try it on longer files and I wanted to see > the change more quickly (without long files scrolling past my terminal), > so I decided to add a /q/ command right after the c commmand. I > thought---it will make sed quit right after making the change, so I can > see it works as desired and then I remove the /q/ and release it to > production. But that did not happen. [snip] > I failed the exercise I gave myself. Can you help me to understand why > the q command isn't stopping sed as I thought it would? I'd like to get > a better intuition. By default sed prints the "pattern space", i.e. all lines in the file. You can suppress that with the "-n" option to sed. (In other words, use "sed -n" instead of plain "sed" in your script.) The man page for GNU sed 4.9 says about the "q" command: "Immediately quit the sed script without processing any more input, except that if auto-print is not disabled the current pattern space will be printed." So the behaviour you're seeing without the "-n" option is to be expected: pattern space still gets auto-printed after the "q" command.