shell 脚本中获取执行系统命令的输出结果
这个主要介绍的方法是获取命令的输出内容,而不是命令执行成功与否的返回值。 通常情况下,在shell脚本中需要获取命令的输出内容,然后根据输出内容判断下一步的执行操作。 比较常用的一种方式就是, 匹配命令输出的内容中是否存在某些关键字,选择执...
这个主要介绍的方法是获取命令的输出内容,而不是命令执行成功与否的返回值。 通常情况下,在shell脚本中需要获取命令的输出内容,然后根据输出内容判断下一步的执行操作。 比较常用的一种方式就是, 匹配命令输出的内容中是否存在某些关键字,选择执...
1.使用grep s1="abcdefg" s2="bcd" result=$(echo $s1 | grep "${s2}") if [[ "$result" != "" ]] then echo "$s1 include $s2" el...
打印匹配行的前后5行 grep -5 ‘something’ file 打印匹配行的前后5行 grep -c 5 ‘something’ file 打印匹配行的后5行 grep -a 5 ‘something’ file...
1、创建测试数据 [[email protected] test]# seq 30 > a.txt [r[email protected] test]# ls a.txt [[email protected] test]# head a...
1、创建测试数据 [[email protected] test]# seq 20 > a.txt [[email protected] test]# ls a.txt [[email protected] test]# head a.txt 1...
1、创建测试数据 [[email protected] test3]# cat a.txt e i j s e f y u d s d g 2、小写转换为大写 tr [[email protected] test3]# tr [a-z...
1、创建测试数据 [[email protected] test3]# cat a.txt wrwrt fdgsaf fsads gdfgde fsddd dffgdf sfdef sdfdsg 2、 [[email protected]...
1、创建测试数据 [[email protected] test3]# echo {1..300} | xargs -n 15 > a.txt [[email protected] test3]# cat a.txt 1 2 3 4 5 6 ...
1、创建测试数据 [[email protected] test3]# cat a.txt w r t f s 4 6 6 a g g s d g r 4 d e w h s f g h 2、 [[email protected] test3]# ...
shell命令从字符串中提取数字 echo "2020年7月21日" | tr -cd "[0-9]" 这样就可以提取出2020721