简体   繁体   中英

Shell script sed - replace numbers

I have a file that contains address, name and phone number.

Original line:

Elizabeth Salnger 117 Someone St - Fresno, CA013023459876AcccountActive 

Expected line:

Elizabeth Salnger 117 Someone St - Fresno, CA099999999999AcccountActive

I have a function

sed -r 's/./&\n/64;s//\n&/52;:a;s/(\n.[0-9]+)[0-9](.*\n)/\1P\2/;ta;s/\n//g' 

Obs: this function is used to convert various files, that's why I have to set position on sed function.

Not sure it's what you look for but you can try this sed :

sed -E 's/(.*,[^0-9]*)[0-9]*(.*)/\1099999999999\2/' infile

If it's ok, i can add explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM