By arunraj
UNIX command to search for multiple patterns in a file. Consider the file containing various phone numbers
phone.txt
234-1765
98403-72594
2242-3319
91-044-26387553
98403-72594
2242-3319
91-044-26387553
The above file contains a list of phone numbers in various formats. Use the following command to search for all the phone numbers in the above file.
cat phone.txt | sed -n "/^[0-9]\{3\}-[0-9]\{4\}/p;/^[0-9]\{4\}-[0-9]\{4\}/p;/^[0-9]\{2\}-[0-9]\{3\}-[0-9]\{4\}/p;"
In the above command each search pattern is separated by a semi colon. The output will be as follows
Output:
234-1765
2242-3319
91-044-26378553
2242-3319
91-044-26378553