【发布时间】:2019-06-12 13:25:35
【问题描述】:
我正在编写一个简短的脚本来使用 fastboot 收集 Android 手机信息。
使用以下命令
fastboot getvar product
我可以得到这样的返回值
product: "name"
Finished. Total time: 0.029s
我只需要字符串“product:”之后的值“name”,所以我尝试使用“:”作为分隔符。我尝试将此线程“How do you extract a specific line from block of text and store them into string variables?”的建议与类似的东西一起使用
fastboot getvar product | awk 'NR==1{print $2}'
或者
fastboot getvar product | awk =F ":" '{print $2}'
或者
fastboot getvar product | sed -n 's/.* //; 1h'
返回值总是
product: "name"
Finished. Total time: x.xxxs
我使用的操作系统是 Debian rodete。任何建议表示赞赏。谢谢。
【问题讨论】:
-
awk -F: 'NR==1{print $2}'应该可以工作。 -
大概 awk 2
=F是-F的拼写错误,而 sed1h应该是1p?
标签: linux bash shell awk debian-based