Reputation: 1
How to extract "oid" from a file with the following structure using shell scripting?
file name :variable
file body:
"title":"script1"
"oid":"jjjnerfjeffrefef6"
"user":"xxxx"
I would like to only extract the oid value (jjjnerfjeffrefef6).
Upvotes: 0
Views: 34
Reputation: 103714
Given:
$ echo "$s"
"title":"script1" "oid":"jjjnerfjeffrefef6" "user":"xxxx"
You can use sed
with a regex:
$ echo "$s" | sed -ne 's/^.*"oid":"\([^"]*\).*$/\1/p'
jjjnerfjeffrefef6
Which would also work for a file:
$ sed -ne 's/^.*"oid":"\([^"]*\).*$/\1/p' file.txt
Upvotes: 1