I have this file named korad
and I need to print all lines of this file that start with "d" and end with number, This is what I tried:
grep "^d*[0-9]$" korad
CodePudding user response:
grep -E '^d(?:.*)\d$' korad
To get all lines starting with d
and ending with a digit
Regex101 Demo
CodePudding user response:
What about this:
grep "^d" korad | grep "[0-9]$"
This first filters the lines, starting with letter "d" and afterwards filters those results with the lines, ending with a number. Like that, you don't need to worry about anything being present between the first and the last character.
In case you don't understand the vertical bar, it's called a pipe, which is (amongst others) explained here.
CodePudding user response:
Suggesting:
grep "^d.*[[:digit:]]$" korad