- 论坛徽章:
- 1
|
[root@mysql01 tmp]# cat /tmp/a.txt
*************** 2017-05-25 10:01:01 ******************
1
2
3
4
5
*************** 2017-05-25 10:10:01 ******************
a
b
c
d
e
*************** 2017-05-25 10:20:01 ******************
m
n
o
p
q
通过sed直接使用两个2017-05-25 10:10:01和2017-05-25 10:20:01值, 取两个字符中间的文本没有问题.
[root@mysql01 tmp]# cat /tmp/a.txt | sed -n '/2017-05-25 10:10:01/,/2017-05-25 10:20:01/p'
*************** 2017-05-25 10:10:01 ******************
a
b
c
d
e
*************** 2017-05-25 10:20:01 ******************
但是如果我将两个变量传入变量a和b后,用sed使用变量a和b取两个值之间的文本就获取不到了,请问哪里有问题?
[root@mysql01 tmp]# a='2017-05-25 10:10:01'
[root@mysql01 tmp]# b='2017-05-25 10:20:01'
[root@mysql01 tmp]# cat /tmp/a.txt | sed -n '/"$a"/,/"$b"/p'
[root@mysql01 tmp]#
[root@mysql01 tmp]# cat /tmp/a.txt | sed -n '/$a/,/$b/p'
[root@mysql01 tmp]#
|
|