I am trying to write a script using grep
to find phone numbers in a text format.
The format for phone numbers is:
(XXXXX) XXXXXX
XXXXX XXXXXX
(XXXXX)XXXXXX
I have written the following script but it doesnt seme to work:
grep -E -o "\b[0-9]\{5\}[0-9]\{6\}\b" webpage.html|
while read phone
do
echo "$phone" >> testp.txt
done
Can someone help?
grep -Eo '\(?[[:digit:]]{5}\)?[[:space:]]?[[:digit:]]{6}' webpage.html > testp.txt
You will need to escape the opening and closing brackets. Search for and opening bracket 0 or 1 times, then 5 digits, a space one or more times and digits 6 times.
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.