I'd like to create a bash script. Therefore, I defined a variable
pattern1=Today,\ 15:46
I had to add a \ before the space " " because otherwise I get the error "command not found"
Now, I used this command to search the pattern in out.txt:
grep -c '$pattern1' out.txt
Here grep doesn't find anything.
However, when I type in
grep -c 'Today, 15:46' out.txt
I get a result.
Also with the following code, I don't get any result:
define pattern2=15:46
grep -c '$pattern2$ out.txt
Where is the mistake? Can grep not look for a previously defined pattern? Is there a trick to look for the pattern anyway?
I'd be grateful for every help!
Kind regards, X3nion
grep -c "$pattern"
– glenn jackman Apr 19 '20 at 18:28pattern1=Today,\ 15:46
is fine, but you could also use quotes here, it might be clearer:pattern1="Today, 15:46"
– ilkkachu Apr 19 '20 at 18:38