regex - Sed or awk extract phone number in whole file -


i'am working on parsing sms numbers email messages , got 1 problem. i'am using awk , sed in bash script. format of phone number sms: +xxx xxx xxx xxx . when there string included in email body need send sms subject. working far got issue when there string multiple on 1 line or after web link. i'am using parse phone numbers array , create files number in name.

phone=( $( awk /sms/ $file | awk '{ gsub (" ", "", $0); print}' ) ) 

works fine when there sms string on separate lines. need same parse string when there more strings on 1 line: sms: +123 456 789 123 sms: +456 789 123 456 or http://somelink/to/some/web/page.html sms: +123 456 789 123 best parse whole file , find after sms: in format +xxx xxx xxx xxx . not sure after last digit line break - might between 2 separate strings. help.

grep -o make life easier:

grep -oe 'sms: \+([[:digit:]]{3} ?){4}' "$file" 

that spit out each match on separate line, no matter how many occur on same line in input.

also, out of habit of using all_caps_varnames. 1 day you'll accidentally use path=... , wonder why script broken.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -