Does the linux regularly match the beginning and end of a specified paragraph (with line breaks)?

clipboard.png if the figure shows a section of the log, you need to count the execution time of this API and the corresponding parameters. That is, all the content between the beginning of the / api/dialog line until the end of the [info] execution time: 1.03604388237 this line. It is very difficult for me to get these contents with grep . I can only take the contents of a certain line, but not across lines.


if you have more information, you can use regular.
provides a foolish extraction scheme for reference:

-sharp!/bin/bash
log=1.txt
getstart=$(cat $log |grep -n "/api/dialog" |awk  -F':' '{print $1}' |xargs)
getlink=$(cat $log |grep -n "^\[" |awk  -F':' '{print $1}' |xargs)
startArray=(${getstart})
linkArray=(${getlink})
for (( i = 0; i < ${-sharplinkArray[*]}; iPP )); do
    for (( j = 0; j < ${-sharpstartArray[*]}; jPP )); do
        if [[ ${startArray[$j]} -eq ${linkArray[$i]} ]]; then
            next=$(expr $i + 2)
            echo "start line:${startArray[$j]}  end line:${linkArray[$next]}"
            content=$(cat $log |sed -n "${startArray[$j]},${linkArray[$next]}p" )
            runTime=$(echo "$content" |grep "" |awk '{print $NF}')
            runParmas=$(echo "$content" |grep -v  "" |grep -v "/api/dialog")
            echo "API info  /api/dialog   runTime: ${runTime} runParmas:${runParmas}"
        fi
    done 
done

use the sed command instead, such as

sed -e '/\/api\/dialog/,//!d' a.txt

corresponds to a.txt file content

[ 0 ] GET /api/hi
[ info ] : 0

[ 1 ] GET /api/dialog
[ info ] : 1

[ 2 ] POST /api/dialog
[ info_api ] array (
    'a' => 2
)
[ info ] : 2

[ 3 ] POST /api/dialog
[ info_api ] array (
    'a' => 3
)
[ info ] : 3

output

[ 1 ] GET /api/dialog
[ info ] : 1
[ 2 ] POST /api/dialog
[ info_api ] array (
    'a' => 2
)
[ info ] : 2
[ 3 ] POST /api/dialog
[ info_api ] array (
    'a' => 3
)
[ info ] : 3
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31cbe-3418c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31cbe-3418c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?