[ILUG] sed advice required...
kor at compsoc.com
Thu Jul 1 22:54:42 IST 2004
> i.e. text_I_want_to_remove=1234=part of string I want
> and text_I_want_to_remove=12345=part of string I want
> ... what I have at the moment is
> sed -e 's/text_I_want_to_remove=[0-9][0-9][0-9][0-9]=//' file ...
The sed regex:
would match and capture a string of length 1 or more consisting of chars 0-9
would match and capture a string of length 0 or more consisting of chars 0-9.
would match and capture a string of length 4 to 6 consisting of chars 0-9.
I'm not sure from your example text, but you might be able to match
portions based on a delimiter, such as '='. If your lines were to be
of the form:
then you could match strings of chars that don't include the delimiter,
separated by the delimiter, like so:
sed -e 's/^\([^=]\+\)=\([^=]\+\)=\(.*\)$/\3/'
The carets in brackets here negate the range of chars in the brackets
... the regex(7) manpage will explain this a helluva lot better than
I will. The only issue then is where to use backslashes to escape
particular special chars such as parentheses, addition-signs, etc.
Every regex-using program - such as perl, sed, vi, or grep - differs
You can watch for your administrator to install the latest kernel with
watch uname -r
-from the manpage for watch(1).
More information about the ILUG