我有一个包含以下数据的文件:
__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脚本实现?
发布于 2019-06-19 16:18:36
您可以使用awk、grep或sed来执行此任务。
以下是几个例子。
注意:提供的示例数据已存储在一个名为sample.txt的文件中。
Awk
# The NF means the number of fields,
# it is used to print the last field
awk '/fdata/ { print $NF }' sample.txt
"telestra"Grep
# Note that this one returns both
# the field label, as well as the value
grep fdata sample.txt
fdata: "telestra"Grep + Sed
# The results of grep are piped into
# sed, which then removes the field name
grep fdata sample.txt | sed 's/fdata: //g'
"telestra"https://stackoverflow.com/questions/56671876
复制相似问题