I am currently using grep to locate a string in a file. However, I get a result I do not want.
Example output:
user@user:~/tmp$ grep "z=" note > tmp.txt | cat tmp.txt
z=0.016728
S_1.4 GHz= 1597.61548 mJy, for L_1.4=1E24 W Hz^-1 (index=0.8)
I do not want to use grep to ignore all results after z=0.016728 because I cannot guarantee that the file structure I am using will always have z= before GHz=.
I would like to ignore anything without a newline or with a character value before z=.
Based on the sample you have given, the simplest option would be to anchor the expression to the start of a line:
Alternatively, you could match only after a word boundary:
See Start of String and End of String Anchors and Word Boundaries
Reread
man grep
, and use Extendedgrep
with a simple Regular expression (and single quotes to avoid shell expandion always):