grep regex solution for finding 3 or more dashes in a string

grep regex hyphen
grep exclude dash
grep regex exclude character
grep regex digit
regex dash
usage: grep (option pattern (file))
grep regex tester
grep number of characters

I'm trying to build a bash script that will look for the keychain folder on a mac and delete it when found using grep. The challenging part is no 2 folders are alike. An example is C0955E7D-DCA1-542B-B506-72A054DET9FA. They all contain 3 or more dashes in the name. Not sure how to grep for this using regex. While in my "~/Library/Keychain/ directory, I was thinking something like...

ls | grep "*-*-*-*"

I was thinking that * would be wildcard and look for any amount of digits that will contain at-least 3 dashes between them.

I'm also opening to using python too (since it comes preinstalled on macs) but that seemed too complicated.


this will print all directory names with 3 or more dashes

find . -type d -exec sh -c '[ $(echo {} | grep -o - | wc -l) -ge 3 ]' \; -print

python, They all contain 3 or more dashes in the name. Not sure how to grep for this using regex. While in my "~/Library/Keychain/ directory, I was  I'm trying to build a bash script that will look for the keychain folder on a mac and delete it when found using grep. The challenging part is no 2 folders are alike. An example is C0955E7D-DCA1-542B-B506-72A054DET9FA. They all contain 3 or more dashes in the name. Not sure how to grep for this using regex.


You can try (\w+-){3,}\w+

Explanation:

\w+ : word characters 1 or more times - : hyphen (\w+-){3,} : some word characters followed by hyphen 3 or more times \w+ : word characters 1 or more times

grep regex solution for finding 3 or more dashes in a string, grep multiple strings and condition grep multiple strings output on same line how to grep multiple words in a single line in unix man grep grep regex hyphen This expression catch only lines that begin with a dash. It does not complies with the initial question. He want to search for a string starting by a dash but the lines that contains this string did not necessary begin with a dash.In the initial question, the string beginning with a dash can be anywhere in the line.


grep ".+-.+-.+-.+" would be more accurate in your case.

. = any character
+ = one or more times (matches any character, one or more times)
(* = zero or more times)

Match with grep when pattern contains hyphen "-", 3. Consider changing your command to grep -Fxc -- "$b" <<< "$a" to avoid the unnecessary Besides of @sebasth's great answer, you could tell that PATTERN with grep's -e option to use Since your goal is byte-to-byte string equality comparison use the [ command instead. Or more portably in all Bourne​-like shells: The grep Linux/Unix command line utility is one of most popular tools for searching and finding strings in a text file. The name “grep” derives from a command in the now-obsolete Unix ed line editor tool — the ed command for searching globally through a file for a regular expression and then printing those lines was g/re/p, where re was the regular expression you would use.


Odd behavior when trying to match hyphens with grep 2.27, When matching hyphens with a [] , the hyphen needs to be first or last within it: grep '[A-Z_-]' If you put the hyphen anywhere else, it will be  REGEX python find previous string. python,regex,string. Updated: This will check for the existence of a sentence followed by special characters. It returns false if there are no special characters, and your original sentence is in capture group 1.


7.8. Searching for an SSN - bash Cookbook [Book], Searching for an SSN Problem You need a regular expression to match a Social Security number. hyphens, so you need to make hyphens optional in the regular expression. Solution. $ grep '[0-9]\{3\}-\{0,1\}[0-9]\{2\}-\{0,1\}[0-9]\{4\}' datafile  Regular Expressions in grep. Regular Expressions is nothing but a pattern to match for each input line. A pattern is a sequence of characters. Following all are examples of pattern: ^w1 w1|w2 [^ ] foo bar [0-9] Three types of regex. The grep understands three different types of regular expression syntax as follows: basic (BRE) extended (ERE


Course: Introduction to Linux, Exercises (continued) Use grep to locate all lines in your file containing the string "this" (all lowercase letters). Now try finding those lines where the first letter of the word "this” is either an upper or lowercase Then write both solutions here: Can you think bash$ _ bash$ grep regex ——— 3 dashes at the beginning. $ apt-cache show grep Description: GNU grep, egrep and fgrep 'grep' is a utility to search for text in files; it can be used from the command line or in scripts. Even if you don't want to use it, other packages on your system probably will. . The GNU family of grep utilities may be the "fastest grep in the west".