Re: [gentoo-user] [OT] Use of sed
On Wed, Jun 24, 2009 at 9:49 AM, Renat Golubchyk wrote: > Man page is very short. Check the info pages for full documentation. > (Almost all tools from GNU userland have a short man page and a long > info page. At least that is what they say right at the bottom.) Also, I have these pages in my bookmarks: http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/sed1line.txt because I can never remember how to do anything without looking it up.
Re: [gentoo-user] [OT] Use of sed
Am Wed, 24 Jun 2009 15:18:02 +0100 schrieb Peter Humphrey : > On Wednesday 24 June 2009 12:28:05 Alex Schuster wrote: > > > man sed answers your second question :) > > s/regexp/replacement/ > Attempt to match regexp against the pattern space. If successful, > replace that portion matched with replacement. The replacement > may contain the special character & to refer to that portion of the > pattern space which matched, and the special escapes \1 through \9 to > refer to the corresponding matching sub-expressions in the regexp. > > No mention of using a different separator, and I couldn't find any > other reference either. I did look before asking. Man page is very short. Check the info pages for full documentation. (Almost all tools from GNU userland have a short man page and a long info page. At least that is what they say right at the bottom.) Section 3.5 (The `s' Command) states in the first paragraph: The syntax of the `s' (as in substitute) command is `s/REGEXP/REPLACEMENT/FLAGS'. The `/' characters may be uniformly replaced by any other single character within any given `s' command. The `/' character (or whatever other character is used in its stead) can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\' character. Cheers, Renat -- Probleme kann man niemals mit derselben Denkweise loesen, durch die sie entstanden sind. (Einstein) signature.asc Description: PGP signature
Re: [gentoo-user] [OT] Use of sed
Peter Humphrey writes: > On Wednesday 24 June 2009 12:28:05 Alex Schuster wrote: > > man sed answers your second question :) > > s/regexp/replacement/ > Attempt to match regexp against the pattern space. If successful, > replace that portion matched with replacement. The replacement may > contain the special character & to refer to that portion of the > pattern space which matched, and the special escapes \1 through \9 to > refer to the corresponding matching sub-expressions in the regexp. > > No mention of using a different separator, and I couldn't find any other > reference either. I did look before asking. Oh, sorry. I thought the german man pages were just translations of the original man pages, but at least the one for sed is entirely different. It also mentions the flags like g to replace globally, not only the first instance. Here is the OpenBSD man page for sed, it has more information. However, this sed is a little different from our GNU sed. For example, it does not have the -i option. http://www.rocketaware.com/man/man1/sed.1.htm Wonko
Re: [gentoo-user] [OT] Use of sed
On Wednesday 24 June 2009 12:28:05 Alex Schuster wrote: > man sed answers your second question :) s/regexp/replacement/ Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp. No mention of using a different separator, and I couldn't find any other reference either. I did look before asking. -- Rgds Peter
Re: [gentoo-user] [OT] Use of sed
Peter Humphrey writes: > I'm reduced to asking a newcomer's question: how can I make sed recurse > down a directory tree? find . -type f -exec sed -i 's/foo/bar/g' '{}' \; > And while I'm at it, how do I change the field > separator from / to enable me to search on that character? Well, just change it :) It does not need to be a /, it is always the first character after the s. sed 's%foo%bar%g' will work just the same. I used to use the ยง character because it is probably not being used in any of my file names, but maybe it was too special, because kate dropped it silently from my shell scripts I edited, and hell broke loose. > I used to have a "SED and AWK" book, but it seems to have walked; and I > can't see anything helpful from a Google search. man sed answers your second question :) Wonko
Re: [gentoo-user] [OT] Use of sed
On Wed, 24 Jun 2009 12:03:19 +0100, Peter Humphrey wrote: > Perhaps. I'm not at my best in the mornings :-( Same here, and it's always morning somewhere :( -- Neil Bothwick Windows artificial intelligence: Unable to FORMAT A: Having a go at C: signature.asc Description: PGP signature
Re: [gentoo-user] [OT] Use of sed
On Wednesday 24 June 2009 10:56:43 Alan McKinnon wrote: > Possibly you were thinking of grep's recursion switch? Perhaps. I'm not at my best in the mornings :-( -- Rgds Peter
Re: [gentoo-user] [OT] Use of sed
On Wednesday 24 June 2009 11:34:18 Peter Humphrey wrote: > On Wednesday 24 June 2009 02:36:08 Neil Bothwick wrote: > > On Wed, 24 Jun 2009 00:48:07 +0100, Peter Humphrey wrote: > > > I'm reduced to asking a newcomer's question: how can I make sed recurse > > > down a directory tree? > > > > You don't, that's not sed's job, which is to edit the text you give it. > > > > Use find to generate a list of files for sed to work on. > > I'll do that. I was confused by a vague memory that there was a recursion > flag somewhere, but I must have been mistaken. sed doesn't do that. sed takes a data stream, bashes it into shape, and outputs a (possibly modified) data stream. How you get the stream in, and what you do with it once it comes out, is up to you. Possibly you were thinking of grep's recursion switch? -- alan dot mckinnon at gmail dot com
Re: [gentoo-user] [OT] Use of sed
On Wednesday 24 June 2009 02:36:08 Neil Bothwick wrote: > On Wed, 24 Jun 2009 00:48:07 +0100, Peter Humphrey wrote: > > I'm reduced to asking a newcomer's question: how can I make sed recurse > > down a directory tree? > > You don't, that's not sed's job, which is to edit the text you give it. > > Use find to generate a list of files for sed to work on. I'll do that. I was confused by a vague memory that there was a recursion flag somewhere, but I must have been mistaken. > > And while I'm at it, how do I change the field > > separator from / to enable me to search on that character? > > By using something else, you don't need to tell sed, it works it out for > itself, just use something that isn't in your search string, : is a good > candidate. The man page makes no mention of that, and when I tried it anyway I got puzzling results, so I assumed it couldn't be done. > Or you can escape the / as \/ but this quickly degenerates into the > leaning matchstick appearance so beloved of Perl scripters. Horrors! Thanks to all for the help. Maybe I should replace that text-book after all. -- Rgds Peter
Re: [gentoo-user] [OT] Use of sed
On 6/24/09, Neil Bothwick wrote: > On Wed, 24 Jun 2009 00:48:07 +0100, Peter Humphrey wrote: >> And while I'm at it, how do I change the field >> separator from / to enable me to search on that character? > > By using something else, you don't need to tell sed, it works it out for > itself, just use something that isn't in your search string, : is a good > candidate. If I read his question right, he asked about just the simple matchers: //. Perl solves this problem with the optional m in front (m//), so you can do m:/foo: or m+/foo+, but I don't know of a similar toggle for sed (well, I'm a sed newbie, so there might still be one). I don't even think substituting the string with itself (s+/foo+/foo+) would work as I think s/// will succeed every time, even when it doesn't actually substitute anything, so maybe it cannot be used for an "if-then" in sed either? -- Arttu V.
Re: [gentoo-user] [OT] Use of sed
On Wed, 24 Jun 2009 00:48:07 +0100, Peter Humphrey wrote: > I'm reduced to asking a newcomer's question: how can I make sed recurse > down a directory tree? You don't, that's not sed's job, which is to edit the text you give it. Use find to generate a list of files for sed to work on. > And while I'm at it, how do I change the field > separator from / to enable me to search on that character? By using something else, you don't need to tell sed, it works it out for itself, just use something that isn't in your search string, : is a good candidate. Or you can escape the / as \/ but this quickly degenerates into the leaning matchstick appearance so beloved of Perl scripters. -- Neil Bothwick Windows Error #01: No error... ...yet. signature.asc Description: PGP signature
Re: [gentoo-user] [OT] Use of sed
On Jun 23, 2009, at 6:48 PM, Peter Humphrey wrote: Hello list, I'm reduced to asking a newcomer's question: how can I make sed recurse down a directory tree? And while I'm at it, how do I change the field separator from / to enable me to search on that character? maybe something like: find . -name '*' -exec sed {options} '{}' \; HTH
[gentoo-user] [OT] Use of sed
Hello list, I'm reduced to asking a newcomer's question: how can I make sed recurse down a directory tree? And while I'm at it, how do I change the field separator from / to enable me to search on that character? I used to have a "SED and AWK" book, but it seems to have walked; and I can't see anything helpful from a Google search. -- Rgds Peter