andersonlizardo at yahoo.com.br
Mon Dec 1 18:28:05 PST 2003
Jason Kircher wrote:
> Or at least I'm trying to make some real use of sed...
First of all, I strongly suggest you read some doc about "Regular
Expressions". It may solve many problems you may enconter while trying
to use regex-ready tools like grep and sed.
> I now have a file which is the result of a multifile grep extracting
> lines out another set of files. grep prepends each line with the
> path of the file processed, followed by ':'. What I'm trying to do
> is to strip the path out of the resulting file. Sounds easy enough
> with sed, right? Guess again.
Initially, you should have used grep's -h option. From its man page:
Suppress the prefixing of filenames on output when
multiple files are searched.
> I tried little experiments like:
> sed 's/:/ /' sitelog
> Nice, it replaced the first colon with a space.
Obvious enough :P
> So you'd figure something like:
> sed 's/.*:/ /' sitelog
> would replace up to the first colon with a single space? Nope... it
Perl's perlrequick manpage says that the
"(...) quantifier '.*' grabs as much of the string as possible while
still having the regex match."
It means that the regex above do what you say it did: it matches the
_longest_ string that contains a ":" on its end.
> matches to the LAST colon in the line, including IP addy, date, much
> of the time, and if the browser version line has a colon in it,
> strips up to that point, so you get something like:
> 1.5a) Gecko/20030829 Mozilla Firebird/0.6.1"
> in the output.
> Reading a little more, and I tried:
> sed 's/.*\(:\)\1//' sitelog
> That hung sed. (^C gets out, thankfully.)
What is that?!? :)
> In short, I want to strip from each line up to and including the
> first colon, and leave the rest alone. I'm trying using the docs, I
> really am, but I'm stuck on this one. What am I doing wrong?
sed 's/^[^:]\+://' sitelog
More information about the lfs-chat