[ILUG] sed advice required...
Kevin O'Riordan
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:
\([0-9]\+\)
would match and capture a string of length 1 or more consisting of chars 0-9
or
\([0-9]*\)
would match and capture a string of length 0 or more consisting of chars 0-9.
or
\([0-9]\{4,6\}\)
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:
someJunkText=12345=someImportantText
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
here.
hth,
-kev
--
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
mailing list