获取shell脚本中的行 [英] getting the line in shell script

查看:33
本文介绍了获取shell脚本中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获得所有"RESP:0,sucess;"在线-输入命令:RESP:0,成功;-这是我的代码.我将如何接受它?

Im trying to get all " RESP:0,sucess;" in line- Enter command:RESP:0,sucess;- here is my codes.how will I take it?

**for i in {2..4}
do 
   date  
   CMDCount="CMD"$i
   eval CMD="$"$CMDCount
   echo "server CMD "${CMD}""${CMDCount}"";
   echo "" 
   (sleep 1;echo $login;
    sleep 1;echo ${CMD};
    sleep 1;echo $logout;sleep 1)|telnet localhost 9685
    sleep 1

done**

输出如下:

server CMD xxxxxxxxxxxxxxxxxxxxxxxxxxxxCMD2

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECTING TO xxx...
PROCESS CPL CONNECTED...
Enter command:RESP:0,sucess;
Enter command:
Enter command: 
Enter command:Connection closed by foreign host.
Sat Aug  3 12:18:21 CST 2013
server CMD xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxCMD3

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECTING TO xxx...
PROCESS CPL CONNECTED...
Enter command:RESP:0,sucess;
Enter command:
Enter command: 
Enter command:Connection closed by foreign host.
Sat Aug  3 12:18:26 CST 2013
server CMD xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;CMD4

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECTING TO xxx...
PROCESS CPL CONNECTED...
Enter command:RESP:0,sucess;
Enter command:
Enter command: 
Enter command:Connection closed by foreign host.

推荐答案

您可能会发现这些链接很有用:

You may find these links useful :

而且,要从整个字符串中提取响应部分,您可以使用以下内容:

And, to extract the response part from the whole string, you can use something like this :

echo `expr "${CMD}" : '\.*?(RESP)(:)(\\d)\'`

这篇关于获取shell脚本中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆