{"thread":{"id":"9372","subject":"Help a sed noob","startedAt":"2007-08-03T23:22:48Z","lastAt":"2007-08-04T14:06:22Z","messageCount":11,"participants":["Nguyen Thai Ngoc Duy","Junio C Hamano","René Scharfe","martin f krafft","Jeff King","Simon 'corecode' Schubert","David Kastrup"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"49639","messageId":"fcaeb9bf0708031622w25ab6e9ev61372169cfc0bd98@mail.gmail.com","threadId":"9372","inReplyTo":null,"subject":"Help a sed noob","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2007-08-03T23:22:48Z","receivedAt":"2007-08-03T23:22:48Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Hi,\n\nThere is a construct like this in git-parse-remote.sh which makes\nbusybox ash unhappy:\n\n                sed -ne '/^URL: */{\n                        s///p\n                        q\n                }' \"$GIT_DIR/remotes/$1\"\n\nIt complains about \"no previous regexp\" while gnu sed is ok. Can\nanyone explain to me what does \"s///p\" do? GNU Sed info page says\nnothing about empty regexp. If I replace it with \"s/\\(.*\\)/\\1/p\" then\nI get \"URL: \" along with the remote path.\n\nBy the way, can we use another construct instead? It would be less\nwork for me ;-)\n-- \nDuy\n"},{"id":"49643","messageId":"7vhcngkx38.fsf@assigned-by-dhcp.cox.net","threadId":"9372","inReplyTo":"fcaeb9bf0708031622w25ab6e9ev61372169cfc0bd98@mail.gmail.com","subject":"Re: Help a sed noob","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-03T23:38:35Z","receivedAt":"2007-08-03T23:38:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com> writes:\n\n> There is a construct like this in git-parse-remote.sh which makes\n> busybox ash unhappy:\n>\n>                 sed -ne '/^URL: */{\n>                         s///p\n>                         q\n>                 }' \"$GIT_DIR/remotes/$1\"\n>\n> It complains about \"no previous regexp\" while gnu sed is ok. Can\n> anyone explain to me what does \"s///p\" do? GNU Sed info page says\n> nothing about empty regexp. If I replace it with \"s/\\(.*\\)/\\1/p\" then\n> I get \"URL: \" along with the remote path.\n\nTraditionally empty LHS regexp means \"the same as last match\".\nReplace it with \"s/^URL: *//p\" and you would be Ok.\n"},{"id":"49644","messageId":"46B3BCE7.3090509@lsrfire.ath.cx","threadId":"9372","inReplyTo":"fcaeb9bf0708031622w25ab6e9ev61372169cfc0bd98@mail.gmail.com","subject":"Re: Help a sed noob","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-08-03T23:40:23Z","receivedAt":"2007-08-03T23:40:23Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Nguyen Thai Ngoc Duy schrieb:\n> Hi,\n> \n> There is a construct like this in git-parse-remote.sh which makes\n> busybox ash unhappy:\n> \n>                 sed -ne '/^URL: */{\n>                         s///p\n>                         q\n>                 }' \"$GIT_DIR/remotes/$1\"\n> \n> It complains about \"no previous regexp\" while gnu sed is ok. Can\n> anyone explain to me what does \"s///p\" do? GNU Sed info page says\n> nothing about empty regexp. If I replace it with \"s/\\(.*\\)/\\1/p\" then\n> I get \"URL: \" along with the remote path.\n> \n> By the way, can we use another construct instead? It would be less\n> work for me ;-)\n\nYou could manually add the previous regular expression, like this:\n\n\t\tsed -ne '/^URL: */{\n\t\t\ts/^URL: *//p\n\t\t\tq\n\t\t}' \"$GIT_DIR/remotes/$1\"\n\nRené\n"},{"id":"49646","messageId":"fcaeb9bf0708031706o3e3f4839t39eca4b64b0aab5d@mail.gmail.com","threadId":"9372","inReplyTo":"7vhcngkx38.fsf@assigned-by-dhcp.cox.net","subject":"Re: Help a sed noob","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2007-08-04T00:06:34Z","receivedAt":"2007-08-04T00:06:34Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Great! Thank you both.\n\nOn 8/3/07, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com> writes:\n>\n> > There is a construct like this in git-parse-remote.sh which makes\n> > busybox ash unhappy:\n> >\n> >                 sed -ne '/^URL: */{\n> >                         s///p\n> >                         q\n> >                 }' \"$GIT_DIR/remotes/$1\"\n> >\n> > It complains about \"no previous regexp\" while gnu sed is ok. Can\n> > anyone explain to me what does \"s///p\" do? GNU Sed info page says\n> > nothing about empty regexp. If I replace it with \"s/\\(.*\\)/\\1/p\" then\n> > I get \"URL: \" along with the remote path.\n>\n> Traditionally empty LHS regexp means \"the same as last match\".\n> Replace it with \"s/^URL: *//p\" and you would be Ok.\n>\n>\n\n\n-- \nDuy\n"},{"id":"49691","messageId":"20070804103126.GA28402@lapse.madduck.net","threadId":"9372","inReplyTo":"fcaeb9bf0708031622w25ab6e9ev61372169cfc0bd98@mail.gmail.com","subject":"Re: Help a sed noob","fromName":"martin f krafft","fromEmail":"madduck@madduck.net","sentAt":"2007-08-04T10:31:26Z","receivedAt":"2007-08-04T10:31:26Z","isPatch":false,"sender":{"key":"madduck@madduck.net","avatar":null},"body":"also sprach Nguyen Thai Ngoc Duy <pclouds@gmail.com> [2007.08.04.0122 +0200]:\n>                 sed -ne '/^URL: */{\n>                         s///p\n>                         q\n>                 }' \"$GIT_DIR/remotes/$1\"\n\nLooks like it prints the first matching line:\n\n  grep '^URL: *' | head -1\n\n-- \nmartin;              (greetings from the heart of the sun.)\n  \\____ echo mailto: !#^.\"<*>\"|tr \"<*> mailto:\" net@madduck\n \nquantum mechanics: the dreams stuff is made of.\n \nspamtraps: madduck.bogus@madduck.net\n"},{"id":"49701","messageId":"20070804115003.GA9716@coredump.intra.peff.net","threadId":"9372","inReplyTo":"20070804103126.GA28402@lapse.madduck.net","subject":"Re: Help a sed noob","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-08-04T11:50:03Z","receivedAt":"2007-08-04T11:50:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Aug 04, 2007 at 12:31:26PM +0200, martin f krafft wrote:\n\n> also sprach Nguyen Thai Ngoc Duy <pclouds@gmail.com> [2007.08.04.0122 +0200]:\n> >                 sed -ne '/^URL: */{\n> >                         s///p\n> >                         q\n> >                 }' \"$GIT_DIR/remotes/$1\"\n> \n> Looks like it prints the first matching line:\n> \n>   grep '^URL: *' | head -1\n\nNo, it prints everything _except_ \"URL: *\" from the first matching line.\n\n-Peff\n"},{"id":"49707","messageId":"20070804121811.GA1605@lapse.madduck.net","threadId":"9372","inReplyTo":"20070804115003.GA9716@coredump.intra.peff.net","subject":"Re: Help a sed noob","fromName":"martin f krafft","fromEmail":"madduck@madduck.net","sentAt":"2007-08-04T12:18:11Z","receivedAt":"2007-08-04T12:18:11Z","isPatch":false,"sender":{"key":"madduck@madduck.net","avatar":null},"body":"also sprach Jeff King <peff@peff.net> [2007.08.04.1350 +0200]:\n> No, it prints everything _except_ \"URL: *\" from the first matching line.\n\nI am convinced we could submit this to the Obfuscated Code Contest.\n:)\n\nThe behaviour is absolutely unclear from the manpage and defies my\nlogic. Can you elaborate a bit, even though this is off-topic?\n\n-- \nmartin;              (greetings from the heart of the sun.)\n  \\____ echo mailto: !#^.\"<*>\"|tr \"<*> mailto:\" net@madduck\n \nkill ugly radio\n                                                        -- frank zappa\n \nspamtraps: madduck.bogus@madduck.net\n"},{"id":"49709","messageId":"46B4705D.2010208@fs.ei.tum.de","threadId":"9372","inReplyTo":"20070804121811.GA1605@lapse.madduck.net","subject":"Re: Help a sed noob","fromName":"Simon 'corecode' Schubert","fromEmail":"corecode@fs.ei.tum.de","sentAt":"2007-08-04T12:26:05Z","receivedAt":"2007-08-04T12:26:05Z","isPatch":false,"sender":{"key":"corecode@fs.ei.tum.de","avatar":"https://gravatar.com/avatar/eff9dbf0cdac0d1e6a6cd7ed0e50763edcb376b493b5253a35ff167918ad79e1?d=mp&s=160"},"body":"martin f krafft wrote:\n> also sprach Jeff King <peff@peff.net> [2007.08.04.1350 +0200]:\n>> No, it prints everything _except_ \"URL: *\" from the first matching line.\n> \n> I am convinced we could submit this to the Obfuscated Code Contest.\n> :)\n\nThis is basic sed scripting.\n\n> The behaviour is absolutely unclear from the manpage and defies my\n> logic. Can you elaborate a bit, even though this is off-topic?\n\n-ne means \"don't print, execute the following code\".\n\n/.../ should be clear, { starts a \"function list\"\ns// is \"match last regexp, so s/// is \"match last regexp and replace with empty string.\nflag \"p\" to function \"s\" means \"print if matched\"\nq is \"quit\".\n\nthat's really straight forward and all documented in my sed(1).\n\ncheers\n  simon\n\n-- \nServe - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /\"\\\nWork - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \\ /\nParty Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \\\nDude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \\\n"},{"id":"49712","messageId":"20070804124005.GA15334@sigill.intra.peff.net","threadId":"9372","inReplyTo":"20070804121811.GA1605@lapse.madduck.net","subject":"Re: Help a sed noob","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-08-04T12:40:05Z","receivedAt":"2007-08-04T12:40:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Aug 04, 2007 at 02:18:11PM +0200, martin f krafft wrote:\n\n> The behaviour is absolutely unclear from the manpage and defies my\n> logic. Can you elaborate a bit, even though this is off-topic?\n\nThe original sed code in question was:\n\n                sed -ne '/^URL: */{\n                        s///p\n                        q\n                }' \"$GIT_DIR/remotes/$1\"\n\nThere are a few things to note:\n  1. -n means \"do not print lines by default\"\n  2. sed addresses consist of an address (in this case a regex meaning\n     \"do this for lines that match the regex\") and a command\n  3. The braces start a set of commands, so that for lines matching the\n     address, we do all of the commands.\n  4. An empty matching portion for a regex means \"use the last regex\".\n\nSo this script comes down to:\n  - don't write any lines except the ones we match\n  - find a line that starts with URL:\n    - replace the URL: part with nothing\n    - print the result\n    - quit\n\nIt could be more simply written as:\n\nsed -ne 's/^URL: *//pq'\n\nwhich uses the substitution as an address, but I don't know whether that\nwas allowed in the original sed.\n\n-Peff\n"},{"id":"49720","messageId":"20070804135630.GC1605@lapse.madduck.net","threadId":"9372","inReplyTo":"46B4705D.2010208@fs.ei.tum.de","subject":"Re: Help a sed noob","fromName":"martin f krafft","fromEmail":"madduck@madduck.net","sentAt":"2007-08-04T13:56:30Z","receivedAt":"2007-08-04T13:56:30Z","isPatch":false,"sender":{"key":"madduck@madduck.net","avatar":null},"body":"also sprach Simon 'corecode' Schubert <corecode@fs.ei.tum.de> [2007.08.04.1426 +0200]:\n> s// is \"match last regexp, so s/// is \"match last regexp and replace with \n> empty string.\n\nThis fact is not in the manpage, AFAICT, at least not on Debian\nsystems.\n\n-- \nmartin;              (greetings from the heart of the sun.)\n  \\____ echo mailto: !#^.\"<*>\"|tr \"<*> mailto:\" net@madduck\n \ndue to lack of interest tomorrow has been cancelled.\n \nspamtraps: madduck.bogus@madduck.net\n"},{"id":"49723","messageId":"85abt7gzs1.fsf@lola.goethe.zz","threadId":"9372","inReplyTo":"20070804135630.GC1605@lapse.madduck.net","subject":"Re: Help a sed noob","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-08-04T14:06:22Z","receivedAt":"2007-08-04T14:06:22Z","isPatch":false,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"martin f krafft <madduck@madduck.net> writes:\n\n> also sprach Simon 'corecode' Schubert <corecode@fs.ei.tum.de> [2007.08.04.1426 +0200]:\n>> s// is \"match last regexp, so s/// is \"match last regexp and replace with \n>> empty string.\n>\n> This fact is not in the manpage, AFAICT, at least not on Debian\n> systems.\n\nIIRC, this is a traditional _ed_ feature.  I don't think it has ever\nbeen a traditional part of _sed_, but maybe some implementations have\nadopted this usage.\n\n-- \nDavid Kastrup, Kriemhildstr. 15, 44793 Bochum\n"}]}