[英]Searching text file in Unix using shell script
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. 我有一个输入文本文件(如下所示),必须在shell脚本中调用它,而且在shell脚本中,我将传递一个输入参数,从输入文本文件中可以找到对应的值。
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
. 因此,如果我的输入参数是
Janan
我必须返回Janan_2
作为输出,或者如果我的输入是Janan_ex1
那么输出将是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
: 将您的输入“文件”以“输入参数”作为参数
...|./bashscript San
到以下bash脚本中,例如...|./bashscript San
:
#!/usr/bin/bash
sed 's/[^ ]*// ; s/}}"}// ; s/"://g ; s/,\\n/\n/g'|
tr -d '\\'|
awk -F\" '$2=="'$1'"{print $3}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.