Link to home
Start Free TrialLog in
Avatar of Hiro 714
Hiro 714

asked on

shell script question

I would like to replace a string with a certain condition.
1. remove a string the 5-digit number after "customer pin =" and replace to #####
example: "customer pin = 12345" to "customer pin = #####"

Avatar of David Favor
David Favor
Flag of United States of America image

One simple approach...

perl -p -i -e 's/12345/#####/' some-file-name

Open in new window

Avatar of Hiro 714
Hiro 714

ASKER

Thank you.
this code does not work. would you adivse?
sed 's/customer pin = \d{5}/customer pin = #####/'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sed, to me, doesn't work sensibly.

With sed you'll likely require using POSIX regular expressions.

The following works for me, with recent version of sed...

sed -ri 's/customer pin = [[:digit:]]{5}/customer pin = #####/g' foo.txt

Open in new window


This is why I normally use PERL instead.