0

I have a file that contains the following data:

__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"

I want to get the value of fdata (telestra). How can I achieve using shell scripting?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
knowledgeseeker
  • 339
  • 4
  • 14

1 Answers1

3

You can use either awk, grep, or sed for this task.

Here are a few examples.

Note: the sample data provided has been stored in a file called 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"
Cyrus
  • 84,225
  • 14
  • 89
  • 153
oxr463
  • 1,573
  • 3
  • 14
  • 34