Reputation: 239
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 ?
Upvotes: 0
Views: 521
Reputation: 8621
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.
Upvotes: 1
Reputation: 36
$ param="A@X"
$ awk '{if($2~/name/) {a=$3} else {print a,$0}}' temp |grep token|grep $param|awk '{print $3}'
abcdefghijk
Upvotes: 2