Linux 线上第九期_Linux 三剑客进阶_20190410

思寒_seveniruby for 霍格沃兹测试学院外部交流圈 · April 10, 2019 · Last by lonely_harry replied at April 22, 2019 · 2036 hits

上节课作业答疑

awk '$7~/topics\/[0-9]+$/{sum+=$(NF-1)}END{print sum/NR}' nginx.log

grep进阶

1004  seq 10
1005 seq 10 | grep 1
1006 seq 10 | grep 2
1007 seq 10 | grep 3
1008 seq 10 | grep '[1-3]'
1009 seq 10 | grep '[1-3]$'
1010 seq 10 | grep '.'
1011 seq 10 | grep '.$'
1012 seq 10 | grep '^.$'
1013 seq 10 | grep '^..$'
1014 seq 10 | grep '5|7'
1015 seq 10 | grep -E '5|7'
1016 seq 10 | grep -oE '5|7'
1017 seq 10 | grep -oE '(5|7)|(10)'
1018* seq 10 | grep -oE '(5)|(10)'
1019 seq 10 | grep 3
1020 seq 10 | grep -A 2 3
1021 seq 10 | grep -B 2 3
1022 seq 10 | grep -C1 3

正则类型

awk进阶

1023  seq 10 | awk '/^..$/'
1024 seq 10 | awk '/^5$/'
1025 seq 10 | awk '/^1$/'
1026 seq 10
1027 seq 20
1028 seq 20 | awk '/[5-9]/'
1029 seq 20 | awk '/[15-19]/'
1030 seq 20 | awk '3,4'
1031 seq 20 | awk '/15/,//19'
1032 seq 20 | awk '/15/,/19/'
1033 seq 20 | awk 'NR=1'
1034 seq 20 | awk 'NR==1'
1035 seq 20 | awk 'NR==2'
1036 seq 20 | awk 'NR==10'
1037 pwd
1038 echo '1|2'
1039 echo '1|2#3_4'
1040 echo '1|2#3_4' | awk -F '#|_' '{print $4}'
1041 echo '1|2#3_4' | awk -F '#|_' '{print $NF}'
1042 echo '1|2#3_4' | awk -F '#|_' '{print $3}'
1043 echo '1|2#3_4' | awk -F '#|_' '{print $2}'
1044 echo '1|2#3_4' | awk -F '#|_' '{print $1}'
1045 echo '1|2#3_4' | awk -F '#|_|' '{print $1}'
1046 echo '1|2#3_4' | awk -F '#|_|\|' '{print $1}'
1047 echo '1|2#3_4' | awk -F '#|_|\\|' '{print $1}'
1048 echo '1|2#3_4' | awk -F '#|_|\\|' '{print $2}'
1049 echo '1|2#3_4' | awk -F '#|_|\\|' '{print $3}'
1050 echo '1|2#3_4' | awk -F '#|_|\\|' '{print $4}'
1051 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|"}{print $4}'
1052 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|"}{print $1}'
1053 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" "}{print $1}'
1054 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" "}{print $0}'
1055 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" ";}{print $0}'
1056 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" ";}{print $1}'
1057 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" ";}{print $1,$2,$3,$4}'
1058 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";}{print $1,$2,$3,$4}'
1059 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS=" "}{print $1,$2,$3,$4}'
1060 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS="_"}{print $1,$2,$3,$4}'
1061 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS="_"}{print $0}'
1062 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS="_"}{print $1,$2,$3,$4}'
1063 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|";OFS="_";}{print $1,$2,$3,$4}'
1064 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|";OFS="_";}{print $1}'
1065 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|";}{print $1}'
1066 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|";ORS="_"}{print $1}'
1067 echo $PATH
1068 echo $PATH | awk 'BEGIN{RS=":"}'
1069 echo $PATH | awk 'BEGIN{RS=":"}{print $0}'

科学计算与词典使用

1072  awk '{print 3*7}'
1073 echo |awk '{print 3*7}'
1074 awk 'END{print 3*7}'
1075 awk 'BEGIN{print 3*7}'
1076 awk 'BEGIN{print 1/3}'
1077 awk 'BEGIN{printf "%f",1/3}'
1078 awk 'BEGIN{printf "%f\n",1/3}'
1079 awk 'BEGIN{printf "%.2f\n",1/3}'
1080 awk 'BEGIN{printf "%.1f\n",1/3}'
1081 awk 'BEGIN{printf "%.f\n",1/3}'
1082 awk 'BEGIN{printf "%.f\n",2/3}'
1083 seq 10
1084 seq 10 20
1085 seq 10 20 3
1086 seq 10 2 20
1087 seq 10 2 20 | awk '{sum+=$1}{print sum}'
1088 seq 10 2 20 | awk '{sum+=$1}{print sum/R}'
1089 seq 10 2 20 | awk '{sum+=$1}{print sum/NR}'
1090 seq 10 2 20 | awk '$1>10{}'
1091 seq 10 2 20 | awk '$1>10'
1092 seq 10 2 20 | awk '$1>14'
1093 seq 10 2 20 | awk '$1>14{data[NR]=$1}'
1094 seq 10 2 20 | awk '$1>14{data[NR]=$1}{print data}'
1095 seq 10 2 20 | awk '$1>14{data[NR]=$1}{for(k in data) print data[k]}'
1096 seq 10 2 20 | awk '$1>14{data[NR]=$1}END{for(k in data) print data[k]}'

sed进阶

1097  seq 10
1098 seq 10 | sed '2p'
1099* seq 10 | sed -n '2p'3
1100 seq 10 | sed '2d'
1101 seq 10 | sed 's#2#xxxx#'
1102 seq 10 | sed 's#1#xxxx#'
1103 seq 10 | sed 's#1$#xxxx#'
1104 seq 10 | sed 's#1$#xxxx#g'
1105 seq 11 21 | sed 's#1$#xxxx#g'
1106 seq 11 21 | sed 's#1#xxxx#g'
1107 seq 11 21 | sed 's#1#xxxx#'
1108 seq 11 21 | sed 's/1/xxxx/'
1109* seq 11 21 | sed 's%1/xxxx/'
1110 seq 11 21 | sed 's/1/xxxx/'
1111 seq 11 21 | sed '2,3,4p'
1112 seq 11 21 | sed '2,4p'
1113 seq 11 21 | sed '/14/,/16/p'
1114 seq 11 21 | sed -n '/14/,/16/p'
1115 seq 11 21 | sed -n '2,4p'
1116 seq 100 120
1117 seq 100 110
1118 seq 100 110 | awk -F0 '{print $NF}'
1119 seq 100 110 | sed 's#...#x#'
1120 seq 100 110 | sed 's#...#x#g'
1121 seq 100 110 | sed 's#..#x#'
1122 seq 100 110 | sed 's#..##'
1123 seq 100 110 | sed 's#..(.)#\1#g'
1124 seq 100 110 | sed -E 's#..(.)#\1#g'
1125 seq 126 134 | sed -E 's#..(.)#\1#g'
1126 seq 126 134
1127 seq 126 134 | sed -E 's#..(.)#\1#g'
1128 seq 126 134 | sed -E 's#.(.)(.)#\1#g'
1129 seq 126 134 | sed -E 's#.(.)(.)#\2#g'
1130 seq 126 134 | sed -E 's#.(.)(.)#\1+\2#g'

Android的Uiautomator命令

#获取android手机的屏幕上的控件列表
adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml"
#<node index="1" text="登录" resource-id="com.sankuai.meituan:id/button_signin" class="android.widget.Button" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[330,1126][750,1246]" />
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1812]"><node index="0" text="登录后可查看订单、收藏记录" resource-id="com.sankuai.meituan:id/text_signin_tips" class="android.widget.TextView" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[267,1027][813,1084]" /><node index="1" text="登录" resource-id="com.sankuai.meituan:id/button_signin" class="android.widget.Button" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[330,1126][750,1246]" /><node index="2" text="" resource-id="" class="android.widget.FrameLayout" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[15,1656][365,1812]"><node index="0" text="首页" resource-id="com.sankuai.meituan:id/tab_name" class="android.widget.TextView" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[157,1754][223,1798]" /></node><node index="3" text="" resource-id="" class="android.widget.FrameLayout" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="true" bounds="[365,1656][715,1812]"><node index="0" text="订单" resource-id="com.sankuai.meituan:id/tab_name" class="android.widget.TextView" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="true" bounds="[507,1754][573,1798]" /></node><node index="4" text="" resource-id="" class="android.widget.FrameLayout" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[715,1656][1065,1812]"><node index="0" text="我的" resource-id="com.sankuai.meituan:id/tab_name" class="android.widget.TextView" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[857,1754][923,1798]" /></node><node index="5" text="订单" resource-id="" class="android.widget.TextView" package="com.sankuai.meituan" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[36,111][132,176]" /></node></hierarchy>

实战 编写Android自动化测试工具

click(){
local index=1
[ -n "$2" ] && index=$2
adb shell input tap \
$(
adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml" \
| sed 's#<node#^<node>#g' \
| awk 'BEGIN{RS="^"}{print $0}' \
| grep "$1" \
| sed -n "$index"p \
| awk 'BEGIN{FS=",|\\[|\\]"}{print ($2+$5)/2,($3+$6)/2}'
)
}

for name in 我的 订单 首页 ;do click $name;done

课后作业

https://testerhome.com/api/v3/topics.json
把里面的每个帖子的信息,都拆分为独立的一行

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 63 条回复 时间 点赞
ovwane 九期测试开发系列进阶课程-汇总贴 中提及了此贴 10 Apr 20:58
curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="},{"}{print "{"$0}'| sed 's/{"topics":\[{//g'

课后作业

curl -s https://testerhome.com/api/v3/topics.json \
| sed -e "s#{\"topics\"\:\[{##" -e "s#}]}##" -e "s#},{#~#g" \
| awk -v RS="~" '$0!~/\n/{print "{" $0 "}"}'

作业答案

curl -s https://testerhome.com/api/v3/topics.json| sed -e 's/^{"topics":\[/,/' -e 's/\]}$//'|awk 'BEGIN{RS=",{"} length!=0 {print "{"$0}'

作业:
方法一:

curl -s https://testerhome.com/api/v3/topics.json | jq -c '.topics[]'

方法二:

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{FS="\\:\\[|]}"}{print $2}' | sed 's/,{/,@{/g' | awk 'BEGIN{RS=",@"}{print $0}' | grep -v "^$"
fenny 回复

先不要用jq,尝试下用三剑客搞定,这是为了强化你们对三剑客的掌握程度。

Ryan · #7 · April 11, 2019
Author only

课后作业

curl -s https://testerhome.com/api/v3/topics.json | sed 's/\"topics\":\[{/___/g' | sed 's/}\]}/___/g' | awk -F '___' '{printf $2}' | awk  'BEGIN{RS="},{"}{print "{" $0 "}"}'

curl -s https://testerhome.com/api/v3/topics.json |sed 's#{"topics":\[##g' |sed 's#]}##g' \
| awk 'BEGIN{RS="}},"}{print $0}' |awk '{if($0!="")print $0}' \
| sed 's/$/}}/g' \
| awk '{if(NR%2==0){printf $0 "\n\n"}else{printf "%s:",$0}}' \
| sed 's/,{"id":/{"id":/g'

curl -s https://testerhome.com/api/v3/topics.json | sed 's/{"id":\([0-9]*\),"title"/@{"id":\1,"title"/g' | awk 'BEGIN{RS="@"}{print $0}'

课后作业
curl https://testerhome.com/api/v3/topics.json | sed 's/{"id"/^{"id"/g' | awk 'BEGIN{RS="^"}{print $0}'

Author only
ivogui 回复

只对{"id"进行替换会有问题,因为每篇文章里面有两个id 文章的和用户的,出题人坏的狠的

zhaoyinggang 回复

哈哈,这个只是整道题的一半,另外一半怕你们吐槽难,没敢放出来。

curl -s https://testerhome.com/api/v3/topics.json | sed 's#topics":\[#},#' | sed 's#},{#^{#g' | awk 'BEGIN{RS="^"}{print $0}'


curl -s https://testerhome.com/api/v3/topics.json | sed 's#,{"id#^,{"id#g' | sed 's#\[#^#' | awk 'BEGIN{RS="^"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="}},{"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{FS="\:\[|]}"}{print $2}'| sed 's#},{#}^{#g' | awk 'BEGIN{RS="^"}{print $0}'

更新,去掉最后的空行

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{FS="\\:\\[|]}"}{print $2}'| sed 's#},{#}^{#g' | awk 'BEGIN{RS="^"}{print $0}' | grep -v "^$"

curl -s https://testerhome.com/api/v3/topics.json | sed 's#{"id":#^{"id":#g' | awk 'BEGIN{RS="^"}{print $0}'

不防丢出来看看,我相信有饥渴的高高手在虎视眈眈的

curl -s https://testerhome.com/api/v3/topics.json | sed 's/}},{/}}^{/g' | awk 'BEGIN{RS="^"}{print $0}'

Author only

curl -s https://testerhome.com/api/v3/topics.json|sed -E 's#{"topics":[##g'|sed -E 's#]}##' |sed -E 's#{"id":[0-9]*,"title":#^&#g'|sed -E 's#}},#}}#g'|awk 'BEGIN{RS="^"}{OFS="{"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed -e 's/{"topics":\[/^/g' -e 's/\]}/^/g' -e 's/},{/}^{/g' | awk 'BEGIN{RS="^"}{print $0}'

  • 因为id有两个,所以匹配第一个后面带title的id

curl -s "https://testerhome.com/api/v3/topics.json" | sed 's#"topics":\[{##g' |sed -r 's#(\{"id":[0-9]*,"title")#^\1#g' | awk 'BEGIN{RS="^"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed -Ee "s#{\"topics\":[##" -e "s#]}##" -e "s#},{#}^{#g" | awk 'BEGIN{RS="^"}{print $0}'

curl -s ${url} | awk 'BEGIN{FS=":\\[\\{|\\}\\]\\}";}{print $2;}' | sed 's#[ ][ ]*#!-empty-!#g' | awk 'BEGIN{RS="^\\{|\\},\\{";}{print $0}' | sed 's#!-empty-!# #g'

curl -s https://testerhome.com/api/v3/topics.json |sed 's/\[{"id"/-----{"id"/g;s/\,{"id"/-----{"id"/g'|awk 'BEGIN{RS="-----"}{print "第"NR"条----" $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="}},{"}{print $0}'

30Floor has been deleted

课后作业

curl -s https://testerhome.com/api/v3/topics.json | sed 's/{"topics":\[{/{"topics":\[@{/'|sed 's/},{/}@{/g' | awk 'BEGIN{RS="@"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="},{"}{print "{"$0}'|sed 's/{"topics":[{//g'|sed 's/}]}//g'
通过},{当做分隔符,再在每行开头添加一个{,最后把头尾多余的符号去掉

我的思路历程🙈

第一步,取出中括号之间的数据[]

curl -s https://testerhome.com/api/v3/topics.json | awk -F '\\[|\\]' '{print $2}'

第二步,找出每个帖子的唯一分割标志,我这里用的{"id":18749,"title",并在每个分隔符的前边插入一个特殊字符#

curl -s https://testerhome.com/api/v3/topics.json | awk -F '\\[|\\]' '{print $2}'| sed -E 's/(\{"id":[0-9]+,"title")/#\1/g'

第三步,最后就简单了,直接用插入的特殊符号来分割每个帖子就可以了

curl -s https://testerhome.com/api/v3/topics.json | awk -F '\\[|\\]' '{print $2}'| sed -E 's/(\{"id":[0-9]+,"title")/#\1/g' | awk 'BEGIN{RS="#"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="},{\"id";}{print "{\"id"$0}' | sed 's#{"id{"topics":\[{#{#'

课后作业
curl -s https://testerhome.com/api/v3/topics.json | sed -Ee 's#{"topics":[{##g' -e 's#}}]}##' | awk 'BEGIN{RS="}},{"}{print $0}'

作业:
curl -s https://testerhome.com/api/v3/topics.json|sed "s/:\[/^/g"| sed "s/}\]/}^/g"| awk 'BEGIN{RS="^"}{print $0}'| sed -n '2p'| sed -E 's/{\"id\":[0-9]+,\"title/^&/g' |awk 'BEGIN{RS="^"}{print $0}'

课后作业:
curl -s https://testerhome.com/api/v3/topics.json | sed 's/{"topics":\[/#/' | sed 's/\]\}/#/' | awk -F '#' '{print $2}' | awk 'BEGIN{RS="},{"}{print $0}'

答题思路:
1、插入分隔符星号,将 }},{ 修改成 }},星号{
ps:星号提交的时候不显示,所以手动星号,hhhh
2、使用awk RS筛选分割

输出结果:

作业:curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="},{"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed -e 's#{"topics":[##g' -e 's#]}##' -e 's#'},{'#},^{#g' |awk 'BEGIN{RS="^"}{print $0}'
sed去掉首尾,sed },{替换},^{ ;再分行。

讲解后使用老师方法练习:

curl -s https://testerhome.com/api/v3/topics.json \
| sed -E 's#\{"id":([0-9]*),"title"#^{"id":\1,"title"#g' \
| awk 'BEGIN{RS="^"}{print $0}'\
| sed 1d

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS=er"},{"id}{print $0}'

课后作业:
curl -s https://testerhome.com/api/v3/topics.json | sed 's#{"id":#@{"id":#g' | awk 'BEGIN{RS="@"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed -e 's#{\"topics\"\:\[##' -e 's#]}##' -e 's#},{#}~{#g' | awk 'BEGIN{RS="~";}{print $0}'

一:$ curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS=","}{print $0}' | grep 'title'

"title":"线上第九期_Linux 三剑客进阶_20190410"
"title":"‘Socket connection was lost’ 问题咨询"
"title":"测试团队服务化该如何产出价值?"
.........

二:curl -s https://testerhome.com/api/v3/topics.json | sed 's#,{"id":#,@{"id":#g' | awk 'BEGIN{RS="@"}{print $0}'

课后作业

curl -s https://testerhome.com/api/v3/topics.json|sed -E 's/}]}/}^]}/;s/topics":/topics":^/;s/open":false}},/open:":false}},split/g' |awk -F '\\^\\[|\\^]' '{print $2}'|awk -v RS="split" '{print $0}'
curl https://testerhome.com/api/v3/topics.json | sed -E 's#.{11}(.*)..#\1#g'|sed -e 's#,{"id"#,~{"id"#g' | awk 'BEGIN{RS="~"}{print $0}'

课后作业
curl -s https://testerhome.com/api/v3/topics.json | sed 's/{"id":([0-9]*),"title"/@{"id":\1,"title"/g' |awk 'BEGIN{RS = "@"}{print $0}'

回帖框为啥不能复制内容呢
curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{FS="\}\}\,\{"}{print $0}' |sed 's#}},{#}},^{#g' | awk 'BEGIN{RS="^"}''{print $0}'

curl -s 'https://testerhome.com/api/v3/topics.json' | awk -F 'topics\\":\\[|\\]}' '{print $2}' | sed 's#},{#}\n{#g'

curl https://testerhome.com/api/v3/topics.json | sed 's#{\"topics\"\:\[##' | sed 's#\]}##' | sed 's#}},{\"id#}},^{\"id#g' | awk 'BEGIN{RS="^"}{print $0}'

curl -s "https://testerhome.com/api/v3/topics.json" | awk -F '\[' '{print $2}' | sed -E 's/("id":)([0-9]*,)("title")/^\1\2\3/g'|awk 'BEGIN{RS="^"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{RS="},{"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | awk 'BEGIN{FS="\:\[|]}"}{print $2}' | sed 's/,{/,@{/g' | awk 'BEGIN{RS=",@"}{print $0}'

fenny 回复

懂得用jq是一个很好的点子,但是第二个方法错误

curl -s https://testerhome.com/api/v3/topics.json \
| sed -E 's#{"id":([0-9]*),"title#^{"id":\1,"title#g' \
|awk 'BEGIN{RS="^"}{print $0;}' \
| sed 1d \
|grep -v "^$"
``

curl -s https://testerhome.com/api/v3/topics.json | sed 's/}},{/}}^{/g' | awk 'BEGIN{RS="^"}{print $0}' | awk -F , '{print $2}'

M 回复

老哥的\n这招是真滴流啤

curl -s https://testerhome.com/api/v3/topics.json | ses/{"topics":[//' | sed -E 's/]}//' | sed -E 's/}\,{/}\n{/g'

summer2325 回复

curl -s https://testerhome.com/api/v3/topics.json |sed -E 's/{"topics":[//' | sed -E 's/]}//' | sed -E 's/}\,{/}\n{/g'

curl -s https://testerhome.com/api/v3/topics.json | sed -e "s#{\"topics\":[{##" -e "s#}]}##" -e "s#},{#~#g" | awk -v RS="~" '$0!~/\n/{print "{"$0"}"}'

curl -s https://testerhome.com/api/v3/topics.json |sed -E 's/\{"id":(.....),"title"/~\{"id":\1,"title"/g'| awk 'BEGIN{RS="~"}{print $0}' 
curl -s https://testerhome.com/api/v3/topics.json| sed -e 's/^{"topics":\[{/{/' -e 's/}}]}/}}/' | sed 's#}},{\"id#}}\n{\"id#g' 
curl -s https://testerhome.com/api/v3/topics.json | sed 's#},{#},^{#g' | awk 'BEGIN{RS="^"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed -E 's#({"id":[0-9]*,"title")#^\1#g' | awk 'BEGIN {RS= "^"}{print $0}'

curl -s https://testerhome.com/api/v3/topics.json | sed  's#{"id":\([0-9]*\),"title"#^{"id":\1,"title"#g' | awk 'BEGIN{RS="^"}{print $0}'

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up