I am new to using regex and need to find a specific word in my text file.I need to find the word beach, how would I specify that it starts with b and contains ch?I have tried using grep '^s.*ch' but that prints out lines that contain it and I just want the word.
Need a regex to find all words that begin with a letter and contain two letters
linux;grep;regular expression
The problem you have is that .* matches any sequence of characters (maybe omitting newline) including spaces.So you want to change this to something which matches just characters which make up a word. How exactly you do this depends on which implementation of regular expressions you are using, and if you want to consider characters from different alphabets. One reasonably portable way is to use [[:alpha:]]*The syntax to match at the start of a word also depends on the implementation. For grep you can use \<.To just get the word there are two options to grep that can help, -o and --color. The former just outputs what is matched and the latter puts out the entire line with the match highlighted.So you probably wantgrep -o '\<b[[:alpha:]]*ch' filename