[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sed expression problem ?

On Sat, Jun 28, 2003 at 12:54:27AM +0100, David selby wrote:
} I am starting to use sed but am having a problem with one expression in ...
} cat /mnt/archive/fluxbox/keys | sed 's/:ExecCommand//g ;s/^Mod4 \(.\) Mod
} 4 \(.\)/WinKey \1\2/g'
} works except I hoped s/\/[^ ]+\///g would match any /path/to/file/ and 
} delete it. It refuses to match.

That's because the + is being interpreted as a literal character. Unless
you really want to avoid matching //, I recommend using a * instead.
If you really need "one or more" rather than "zero or more" use \{1,\}
(where \{n,m\} means between n and m occurrences, inclusive, and either n
or m may be omitted).

Furthermore, it's worth pointing out that you need not use the / character
as your delimiter; s:/[^ ]*/::g will work equally well and there won't be
the confusion of escaping the delimiter character in the pattern. The first
character after s, whatever it is (well, I think it can't be a \ but I'm
not sure), is the delimiter.

} Any ideas ?
} Dave
} PS these hyroglypics are starting to make some sense ....

Reply to: