I am writing a script currently that is searching inside a txt file.
So basically I have a loop that grabs a name from a txt file and then searches for that name in another file (file2), but I am having issues.
name=flex
grep $name file2 > file2output
So if file2 (file I am searching inside of) has something like
1 flex-inside
2 flex
1 flex-end
It will match all three of those when I only want it to match the exact string flex.
I want it to only match
2 flex
I was trying to do something where it would look for whatever is in $name and then \n. But nothing is working.
Thank you for the help.
grep -Fx "$name" filegrep -Fw "$name" file. And, don't just say "no luck." That's useless. Tell us exactly what happened: Was there an error? If so, show us the complete error message. Was there too much or too little output? If so, what exactly what was the output?grep -Fw "$name"produces output butgrep -Fx "$name" filedoes not, that means that you have characters, invisible or otherwise, before or afterflexin that line. Ifgrep "$name$" fileworks for you, that means that those characters, visible or not, are beforeflex. Try runninghexdump -C fileand see what extra characters are on theflexline.grep " $name$" filewhere there is a space before$nameand, the final$is the regex symbol for end-of-the-line.aflexorbflexas wellflex