Given a file file1
with this text:
JavaScript
x
Anah, Julio, 5-3871 Ghin, Ermen, 4-4123 Jones, Thomas, 1-4122 Solor, R]ehard, 5-2522 Salazar, Hex, 8-2321 Jones, Tommy, 5-2911 Kar, Rt, 3-3633.
I want to use egrep
to search all the numbers that start with 5 and end with 1.
I have tried:
JavaScript
grep '5' '1' file1
Advertisement
Answer
This regex will work
JavaScript
egrep -o \b5[0-9-]*1\b inputfile
Regex Breakdown
JavaScript
\b # word boundary
5 #Number starts with 5
[0-9-]* #Any combination of 0-9 and -
1 # Ends with 1
\b Word boundary