Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help making a bash shell script that searched for words within words in a

ID: 3689682 • Letter: I

Question

I need help making a bash shell script that searched for words within words in a certain way.

When you use the grep command it prints all results for that word in a file. My code must do this only it can allow anything inbetween the word as well

Basically this command grep -e 'w.*e' if I'm searching for the word we.

In this example while and wee would be results but edward would not.

I tried making a shell script that concatanates the '.* syntax and then executing grep -e $var $filename but it doesn't work because grep tries looking for 'w.*e' exactly like that instead of reading the wildcard syntax.

I really could use some help here, thanks!

Explanation / Answer

Hello there ,

grep -e "w[A-Za-z ]e" myfile1.txt

see my file below and command.

vi myfile1.txt

Hello                                                                                                                                                                                      

I am Dipal                                                                                                                                                                                 

These are my friends.                                                                                                                                                                      

We are going to market                                                                                                                                                                     

wee                                                                                                                                                                                        

woe.

skjkhfskwre   

COMMAND:

bash-4.3$ grep "w[A-Za-z ]e" myfile1.txt                                                                                                                                                   

wee                                                                                                                                                                                        

woe.                                                                                                                                                                                       

skjkhfskwre

Try that and let me know if you have any queries .

Thanks.

To pass as an argument , check below.

bash-4.3$ var="w[A-Za-z ]e"

bash-4.3$ grep -e "$var" myfile1.txt    

wee   

lkfdjkjkfg wrelf                                                                                                                                                                           

asdfkweer

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote