在打开和关闭花括号之间获取字符串

时间:2015-10-28 06:41:18

标签: linux bash shell unix awk

我的文件包含

{"value":true,"message":"fail","timestamp":1445956265,"data":"off

"value":true,"message":"error","timestamp":1445956265,"data":"off"}

我想通过排除{}来提取大括号之间的2行以上

预期输出应该是,

"value":true,"message":"fail","timestamp":1445956265,"data":"off

"value":true,"message":"error","timestamp":1445956265,"url":"off"

我正在使用shell脚本。怎么做......?

2 个答案:

答案 0 :(得分:0)

AWK

awk 'sub("[{}]","")' filename

答案 1 :(得分:0)

尝试:

#!/bin/bash
FILE="temp.txt"
if [[ ! -f $FILE ]]; then
        echo "File not found: $FILE"
        exit 1
fi
out=$(awk 'sub("[{}]","")' $FILE | grep '"value":true')
if [[ ! -z $out ]]; then
        for i in $out; do
                echo "i= $i"
        done
fi