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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.