0

I have a file that contain list of users and his token value like :

- name: A@X/xxxxxx:123
  user:
    token: abcdefghijk
- name: B@Y/yyyyyyy:456
  user:
    token: dassafsdfscczcz

I want to get token value for specific name using bash script ?

4
  • 2
    Is this a YAML file? Don't parse it with non-syntax aware tools. Commented Sep 28, 2018 at 9:03
  • i edited the post , i need to get token value for specific name Commented Sep 28, 2018 at 9:07
  • Install a proper YAML parser - github.com/0k/shyaml Commented Sep 28, 2018 at 9:17
  • Is there is bash Script ? Commented Sep 28, 2018 at 9:20

2 Answers 2

2
$ param="A@X"
$ awk '{if($2~/name/) {a=$3} else {print a,$0}}' temp |grep token|grep $param|awk '{print $3}'
abcdefghijk
Sign up to request clarification or add additional context in comments.

Comments

1

You can use grep:

grep -A 2 "A@X/xxxxxx:123" THEDATAFILE | grep token | cut -d':' -f2

It will work even if you have the same user twice and print both tokens.

Tested with GNU grep on Linux.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.