Reputation: 25
I am trying to make a command to get all the files from the current folder and it's subtree that ends with a suffix then them need to contain lines which start's with a capital letter and and with !. I spent some to find a solution. I only found how to print the lines which starts with capital character but i don't know how to put in the command that '!'.
This is to find all the files which contains a line starting with a capital letter. How do i add to look for lines which ends with !.
find . -type f -exec grep -l "^[A-Z]+*" {} +
Upvotes: 0
Views: 197
Reputation: 1129
find . -type f -name '*suffix' -print0 | xargs -r0 grep -le '^[A-Z].*!$'
should do what you want.
It find
s all files (-type f
) with a suffixed name (-name '*suffix'
) and feeds those files to grep
using xargs
. The regular expression then finds lines that begin with a capital and end with an exclamation mark.
The problem here is mostly quoting. The !
is special in bash (and other shells) and refers to the history. You need to escape it, either by using single quotes or escaping it, by prepending a backslash.
Upvotes: 0
Reputation: 785038
You can use this regex in grep
:
find . -type f -exec grep -El '^[[:blank:]]*[A-Z].*![[:blank:]]*$' {} +
Upvotes: 1
Reputation: 3215
Following syntax will be useful. If am getting the question right this is the solution for you:
find . -type f -name '*!.*' -exec grep -l "^[A-Z]+*" {} +
Upvotes: 0