I have an input text file (shown below) which I have to call in a shell script and also in shell script I will pass an input argument for which I have find a corresponding value from the input text file.
So if my input argument is Janan
I have to return Janan_2
as output, or if my input is Janan_ex1
then output will be Janan_loc_data
.
Input:
"data":"{\"collection\":{\n \"Janan\":\"Janan_2\",\n \"Janan_ex1\":\"Janan_loc_data\",\n \"Neha\":\"Neha_1\",\n \"cric\":\"cric_2\",\n \"San\":\"San_1\",\n \"Arp\":\"Arp_1\",\n \"Nipun_test4\":\"Nipun_test3\",\n \"tran_Nipun\":\"tran_Nipun_2\",\n \"Zing\":\"Zing_1\"}}"}
Pipe your input "file" into the following bash script with your "input argument" as the argument, eg ...|./bashscript San
:
#!/usr/bin/bash
sed 's/[^ ]*// ; s/}}"}// ; s/"://g ; s/,\\n/\n/g'|
tr -d '\\'|
awk -F\" '$2=="'$1'"{print $3}'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.