Before:
main 2>&1 | tee -a $log_file;
This is working fine but it is throwing stderr in $log_file as shown below. I want to replace:
"ERROR (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)"
With:
"NOTE (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)"
I want the version and date to be in regex format.
After:
main 2>&1 | tee -a | sed -i 's|ERROR (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)|NOTE (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)|g' $log_file;
You should precise your need, it's pretty hard to read your code by now.
There is two option here :
First option
I can't test it, however, it should be like this :
main 2>&1 | SED COMMAND | tee -a $log_file
Second option
Tested, it works.
sed -i "s/ERROR (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)/NOTE (version 5.3.0.0-213, build 1 from 2015-02-02_12-17-08 by buildguy) : (stderr)/g" $log_file
Sed will edit the file specified inline because of -i option.
REGEX
If you want to change all ERROR by NOTE , then, you should just use this sed command
sed -i "s/ERROR/NOTE/g" $log_file;
And if you want to be more specific, take a look at this answer : using SED with wildcard
Could you try this;
main 2>&1 | sed "/ERROR.*[0-9]\{1\}.[0-9]\{1\}.[0-9]\{1\}.[0-9]\{1\}-[0-9]\{3\}.*20[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}.*(stderr)/ s/ERROR/INFO/" | tee -a $log_file
To find version, the regex;
[0-9]\{1\}.[0-9]\{1\}.[0-9]\{1\}.[0-9]\{1\}-[0-9]\{3\} :
To find date, regex : for example (2015-02-02_12-17-08)
20[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}
if date is like 2015-12-03 11.37.25, you should use
20[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}.[0-9]\{2\}.[0-9]\{2\}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.