Reputation: 2172
I will be writing a shell script to go through the log file generated by my application , I need to separate out only function names and minimum info about the call from the logs generated.
Log file format will be -
0.0003 636488 +440 -> include_once(/var/www/public/const.php) /var/www/public/ajax_shop.php:2
Now, out of such line I want to extract that - "include_once" was called at line "2" from the file "ajax_shop.php"
how should I use regular expression in shell script for this situation ?
Upvotes: 2
Views: 1360
Reputation: 17054
One way using sed:
sed 's/.*-> \([^(]*\).*:\(.*\)/\1 was called at line \2/' logfile
include_once was called at line 2.
\([^(]*\) => This matches till a closing bracket is encountered. [^(]* => Means a series of characters which is not a '('.
Using awk:
$ awk -F"[>(:]" '{print $2 " was called at line " $NF}' logfile
include_once was called at line 2.
awk uses multiple delimiters >,( and :. Using this, it becomes simple just to print the 2nd field and the last field.
Upvotes: 3