0

I am trying to replace a list of numbers, into "a" letter.

I have been able to do this already in an online regex tester as you can find here.

Example: 123,456,789 ==> 123,a,a

But, I translated this into sed command, like this, and it's not working.

echo "123,456,789" | sed 's/\(\d*\)\(,\d*\)/\1,a/g'

Which produces:

123,a456,a789

Am I missing something?

Mayday
  • 4,680
  • 5
  • 24
  • 58
  • Use `sed 's/\([0-9]*\)\(,[0-9]*\)/\1,a/g'` – Wiktor Stribiżew Jul 20 '18 at 06:55
  • see also: [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – Sundeep Jul 20 '18 at 07:36
  • also note that `echo "123,456,ABC" | sed 's/\([0-9]*\)\(,[0-9]*\)/\1,a/g'` will give `123,a,aABC` because `*` quantifier matches **zero** or more – Sundeep Jul 20 '18 at 07:39

1 Answers1

1

This simple sed might help you:

$ sed -r 's/,[0-9]+/,a/g' <<< "123,456,789"
123,a,a
PesaThe
  • 7,259
  • 1
  • 19
  • 43