[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command to terminate current stream processing

From: Konstantin Andreev
Subject: Command to terminate current stream processing
Date: Tue, 09 Apr 2019 10:00:45 +0300
User-agent: Mozilla/5.0 (X11; SunOS i86pc; rv:31.0) Gecko/20100101 Thunderbird/31.6.0


sed has convenient commands "q" and "Q" that allow to break stream processing, 
if you are not interested in the stream any more. E.g., looking for C header inclusion guard may be

| $ sed -n '/^#ifndef\>/{p;q}' path/to/some.h

Let notice how "q/Q" interact with "-s" (multiple stream processing) option.

If I understand correctly, the option "-s" has evolved as a side effect of "-i" 
option, and, as such, is assumed to work as shortcut that turns iterators like

| $ for j in A B C; do sed SCRIPT $j; done

into the

| $ sed -s SCRIPT A B C

However, "-s" does not work this way if SCRIPT encounters q/Q command: sed just quits 
without processing further streams. Formally correct and agreed with documentation, this breaks 
"-s" option idea.

I believe this is because in past times, when sed was able to process only one stream at one run, 
"terminate stream" and "terminate sed" were the same, and documentation for 
"q/Q" didn't care about the difference.

Anyway, the action of "q/Q" in multi-stream environment is now beyond changing.

But, ... may we introduce a new command, that behaves identically to "q" in a 
single-stream environment, but just breaks current stream processing in a multi-stream 

Konstantin Andreev.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]