With BSD sed
or recent versions of GNU and busybox sed
, you may use
sed -E 's/uid=.+/uid=something/'
to match a single character one or more times.
The -E
flag to sed
enables extended regular expressions. Without it you get basic regular expressions. The two sets of regular expression grammars are largely the same but uses slightly different syntax, and the extended set supports more operators.
This would replace
uid=110
with
uid=something
If you want to match the same character --not with BSD sed
--:
sed -E 's/uid=(.)\1*/uid=something/'
This would replace
uid=110
with
uid=something0
Standard EREs don't have back-references. GNU sed
supports it as an extension, but not BSD sed
. Back-references are a feature of standard BREs though, so you can do:
sed 's/uid=\(.\)\1*/uid=something/'
portably.
sed s/uid=.\+/
– May 05 '17 at 14:35+
requires extended regexes or a backslash, see this question for details. – ilkkachu May 05 '17 at 14:43