如何使用sed命令提取数据 [英] how to extract the data using sed command
本文介绍了如何使用sed命令提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数据
&mac=1E-30-6C-A2-47-5F&ip=172.16.1.127&msk=255.255.255.0&gw=172.16.1.1&pdns=0.0.0.0&sdns=0.0.0.0&Speed=0&PortNo=10001&PerMatFram=0&ComPort=0
我想使用sed commond like提取数据字符串并将其存储在变量中
I want to extract the data string and store it in a variable using sed commond like
ip=172.16.1.127
mac=xyz
如何在上述字符串中使用sed?
How to use sed with the above string?
我已经尝试过使用
IP=`echo "$QUERY_STRING" | sed -n '/&ip=/,/&)/g'
但它没有提供任何数据.
but it is not giving any data.
推荐答案
如果数据不包含任何特殊字符,则可以使用以下代码:
If you data do not contain any special characters, you can use the following:
eval $( echo "$QUERY_STRING" | sed 's/&/ /g' )
这将直接从查询字符串中创建变量,如mac=1E-30-6C-A2-47-5F
等.但是要小心,因为攻击者可能会请求带有以下查询字符串的页面:
That would create variables directly from the query string as mac=1E-30-6C-A2-47-5F
etc. Be careful, though, as an attacker might request a page with the following query string:
&IFS=.&PWD=/&UID=0
另请参见如何从bash CGI脚本中解析$ QUERY_STRING .
这篇关于如何使用sed命令提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文