例如截取日志信息中的json类型的输入信息:

 

linux Shell脚本截取字符串_json

 

 

 

 

脚本如下:

#!/bin/sh
IFS=""
testfile=$1
while read -r line
do
    echo $line
    test1=${line##*'签名验证错误'}
    test1=${test1%currentid*}
    echo $test1
    ##res_code=`echo $test1 | python -c 'import sys, json; print(json.load(sys.stdin)['order_complete_time'])'`
    ##echo $res_code
    ##exit
    ##temp= echo $line | cut -d "\""  -f 19
    ##if [ -n "$temp" ]; then
    ##    echo $temp
    ##fi
done < $testfile