git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Help a sed noob

From
Jeff King <peff@peff.net>
Date
Aug 4, 2007, 12:40 UTC
Message-ID
<20070804124005.GA15334@sigill.intra.peff.net>
In-Reply-To
<20070804121811.GA1605@lapse.madduck.net>
On Sat, Aug 04, 2007 at 02:18:11PM +0200, martin f krafft wrote:
> The behaviour is absolutely unclear from the manpage and defies my
> logic. Can you elaborate a bit, even though this is off-topic?
The original sed code in question was:
                sed -ne '/^URL: */{
                        s///p
                        q
                }' "$GIT_DIR/remotes/$1"
There are a few things to note:
  1. -n means "do not print lines by default"
  2. sed addresses consist of an address (in this case a regex meaning
     "do this for lines that match the regex") and a command
  3. The braces start a set of commands, so that for lines matching the
     address, we do all of the commands.
  4. An empty matching portion for a regex means "use the last regex".
So this script comes down to:
  - don't write any lines except the ones we match
  - find a line that starts with URL:
    - replace the URL: part with nothing
    - print the result
    - quit
It could be more simply written as:
sed -ne 's/^URL: *//pq'

which uses the substitution as an address, but I don't know whether that was allowed in the original sed.

-Peff
Previous: David Kastrup
Message 11 of 11 in “Help a sed noob”
  1. Nguyen Thai Ngoc DuyAug 3, 2007
  2. Junio C HamanoAug 3, 2007
  3. Nguyen Thai Ngoc DuyAug 4, 2007
  4. René ScharfeAug 3, 2007
  5. martin f krafftAug 4, 2007
  6. Jeff KingAug 4, 2007
  7. martin f krafftAug 4, 2007
  8. Simon 'corecode' SchubertAug 4, 2007
  9. martin f krafftAug 4, 2007
  10. David KastrupAug 4, 2007
  11. Jeff KingAug 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.