* [gentoo-user] [OT] Use of sed
@ 2009-06-23 23:48 Peter Humphrey
2009-06-23 23:59 ` Roy Wright
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Peter Humphrey @ 2009-06-23 23:48 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-23 23:48 [gentoo-user] [OT] Use of sed Peter Humphrey
@ 2009-06-23 23:59 ` Roy Wright
2009-06-24 1:36 ` Neil Bothwick
2009-06-24 11:28 ` Alex Schuster
2 siblings, 0 replies; 14+ messages in thread
From: Roy Wright @ 2009-06-23 23:59 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-23 23:48 [gentoo-user] [OT] Use of sed Peter Humphrey
2009-06-23 23:59 ` Roy Wright
@ 2009-06-24 1:36 ` Neil Bothwick
2009-06-24 8:52 ` Arttu V.
2009-06-24 9:34 ` Peter Humphrey
2009-06-24 11:28 ` Alex Schuster
2 siblings, 2 replies; 14+ messages in thread
From: Neil Bothwick @ 2009-06-24 1:36 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 1:36 ` Neil Bothwick
@ 2009-06-24 8:52 ` Arttu V.
2009-06-24 9:34 ` Peter Humphrey
1 sibling, 0 replies; 14+ messages in thread
From: Arttu V. @ 2009-06-24 8:52 UTC (permalink / raw
To: gentoo-user
On 6/24/09, Neil Bothwick <neil@digimed.co.uk> 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.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 1:36 ` Neil Bothwick
2009-06-24 8:52 ` Arttu V.
@ 2009-06-24 9:34 ` Peter Humphrey
2009-06-24 9:56 ` Alan McKinnon
1 sibling, 1 reply; 14+ messages in thread
From: Peter Humphrey @ 2009-06-24 9:34 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 9:34 ` Peter Humphrey
@ 2009-06-24 9:56 ` Alan McKinnon
2009-06-24 11:03 ` Peter Humphrey
0 siblings, 1 reply; 14+ messages in thread
From: Alan McKinnon @ 2009-06-24 9:56 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 9:56 ` Alan McKinnon
@ 2009-06-24 11:03 ` Peter Humphrey
2009-06-24 11:19 ` Neil Bothwick
0 siblings, 1 reply; 14+ messages in thread
From: Peter Humphrey @ 2009-06-24 11:03 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 11:03 ` Peter Humphrey
@ 2009-06-24 11:19 ` Neil Bothwick
0 siblings, 0 replies; 14+ messages in thread
From: Neil Bothwick @ 2009-06-24 11:19 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 261 bytes --]
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:
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-23 23:48 [gentoo-user] [OT] Use of sed Peter Humphrey
2009-06-23 23:59 ` Roy Wright
2009-06-24 1:36 ` Neil Bothwick
@ 2009-06-24 11:28 ` Alex Schuster
2009-06-24 14:18 ` Peter Humphrey
2 siblings, 1 reply; 14+ messages in thread
From: Alex Schuster @ 2009-06-24 11:28 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 11:28 ` Alex Schuster
@ 2009-06-24 14:18 ` Peter Humphrey
2009-06-24 14:44 ` Alex Schuster
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Peter Humphrey @ 2009-06-24 14:18 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 14:18 ` Peter Humphrey
@ 2009-06-24 14:44 ` Alex Schuster
2009-06-24 14:49 ` Renat Golubchyk
2009-06-24 14:55 ` [gentoo-user] " Grant Edwards
2 siblings, 0 replies; 14+ messages in thread
From: Alex Schuster @ 2009-06-24 14:44 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 14:18 ` Peter Humphrey
2009-06-24 14:44 ` Alex Schuster
@ 2009-06-24 14:49 ` Renat Golubchyk
2009-06-24 15:00 ` Paul Hartman
2009-06-24 14:55 ` [gentoo-user] " Grant Edwards
2 siblings, 1 reply; 14+ messages in thread
From: Renat Golubchyk @ 2009-06-24 14:49 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 1519 bytes --]
Am Wed, 24 Jun 2009 15:18:02 +0100
schrieb Peter Humphrey <peter@humphrey.ukfsn.org>:
> 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)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [gentoo-user] Re: [OT] Use of sed
2009-06-24 14:18 ` Peter Humphrey
2009-06-24 14:44 ` Alex Schuster
2009-06-24 14:49 ` Renat Golubchyk
@ 2009-06-24 14:55 ` Grant Edwards
2 siblings, 0 replies; 14+ messages in thread
From: Grant Edwards @ 2009-06-24 14:55 UTC (permalink / raw
To: gentoo-user
On 2009-06-24, Peter Humphrey <peter@humphrey.ukfsn.org> wrote:
> 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.
Apparently that's something that everybody "just knows" so it
doesn't need to go in the man page. :)
It is, however, in the 'info' page:
The s' Command
===============
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.
--
Grant Edwards grante Yow! BARBARA STANWYCK makes
at me nervous!!
visi.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [gentoo-user] [OT] Use of sed
2009-06-24 14:49 ` Renat Golubchyk
@ 2009-06-24 15:00 ` Paul Hartman
0 siblings, 0 replies; 14+ messages in thread
From: Paul Hartman @ 2009-06-24 15:00 UTC (permalink / raw
To: gentoo-user
On Wed, Jun 24, 2009 at 9:49 AM, Renat Golubchyk<ragermany@gmx.net> 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.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-06-24 15:10 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-23 23:48 [gentoo-user] [OT] Use of sed Peter Humphrey
2009-06-23 23:59 ` Roy Wright
2009-06-24 1:36 ` Neil Bothwick
2009-06-24 8:52 ` Arttu V.
2009-06-24 9:34 ` Peter Humphrey
2009-06-24 9:56 ` Alan McKinnon
2009-06-24 11:03 ` Peter Humphrey
2009-06-24 11:19 ` Neil Bothwick
2009-06-24 11:28 ` Alex Schuster
2009-06-24 14:18 ` Peter Humphrey
2009-06-24 14:44 ` Alex Schuster
2009-06-24 14:49 ` Renat Golubchyk
2009-06-24 15:00 ` Paul Hartman
2009-06-24 14:55 ` [gentoo-user] " Grant Edwards
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox