-1

https://regex101.com/r/t1Etzx/1/ is doing the regex substitution ok. using sed 4.2.1 on bash:

echo "text curl -u a12345:ypB7HuW9u5yB'_'https://mycompany.com/api/healthcheck"|sed -r 's/(a\d+|A\d+|scl[^:]+):([^\']+)(\'|_)/\1:xxxxx\3/g'

and

echo "text curl -u a12345:ypB7HuW9u5yB'_'https://mycompany.com/api/healthcheck"|sed -E 's/(a\d+|A\d+|scl[^:]+):([^\']+)(\'|_)/\1:xxxxx\3/g'

are giving me

bash: syntax error near unexpected token `)'

A solution in awk welcome too.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Mikeht
  • 23
  • 4

1 Answers1

0

As mentioned in comments, \d doesn't work, so i replaced it with [0-9]. Also replaced (\'|_) with [\'_], because that didn't work either. As for the bash: syntax error near unexpected token ')', replace single quotes with double quotes, because '\'' doesn't work, because \ in single quotes is literal. So that seems to work:

sed -E "s/(a[0-9]+|A[0-9]+|scl[^:]+):([^\'_]+)([\'_])/\1:xxxxx\3/g"
tbielaszewski
  • 739
  • 3
  • 6
  • 1
    You should not answer such evident duplicates. It is common knowledge POSIX regex does not support `\d`. Just flag these questions as duplicates. – Wiktor Stribiżew Oct 19 '20 at 17:24