我有一个包含以下数据的文件:
__NV__: 1
name: "MEP-UI-CUSTOMER-INFO-TXT"
desc: "MEP Customer Name Information"
fpath: "mep/frontend/ui/primecast/assets/i18n/custom-info.txt"
fdata: "telestra"
我想获取 fdata (telestra( 的值。如何使用 shell 脚本实现?
您可以使用
awk
、grep
或sed
来完成此任务。
以下是一些示例。
注意:提供的示例数据已存储在名为 sample.txt
的文件中
呜
# The NF means the number of fields,
# it is used to print the last field
awk '/fdata/ { print $NF }' sample.txt
"telestra"
格雷普
# Note that this one returns both
# the field label, as well as the value
grep fdata sample.txt
fdata: "telestra"
格雷普 + 塞德
# The results of grep are piped into
# sed, which then removes the field name
grep fdata sample.txt | sed 's/fdata: //g'
"telestra"