Can anyone help me with this:
I am trying to extract a time stamp, by matching a string. For this am using combination of grep/awk commands. As the sting has 4 spces before [1] and one after, am confused how to work around it. Am new to programming, so need some help here.
IS="$(grep 'Starting [1] TaskInit' process.log | awk '{print $4}')"
echo "$IS"
Aim: It should match the string in the process.log file and should print out the time stamp related to that row.
The spaces are not the problem here, it should work fine.
But the brackets
[
need to be escaped in regex. So write:In your case, as you want to match a fixed string and not a regex, you should use
grep -F
instead. Then you don't need to escape:You just need to escape the square brackets, because they have special meaning:
In addition I would use only
awk
for this task, for this purpose you need something like: