我的文件包含
{"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脚本。怎么做......?
答案 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