使用sed提取行范围 [英] Extract range of lines using sed

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

问题描述

我定义了两个变量,如下所示:

I have defined two variables as follows:

var1=$(unzip -c ./*.zip | grep -n "Channel8"| cut -f1 -d":")
var2=$(unzip -c ./*.zip | grep -n "Channel10"| cut -f1 -d":")

我的文件很大,我想使用sed提取 $ var1 $ var2 之间的行范围.我正在尝试以下

I have a very big file and I would like to extract the range of lines between $var1 and $var2 using sed. I am trying the following

sed -n '/"$var1","$var"2p' $(unzip -c ./*.zip)

但是没有成功.您能否解释为什么以及如何解决?谢谢.

But with no success. Could you give an explanation why and how to fix it? Thanks.

推荐答案

您可以使用:

unzip -c ./*.zip | sed -n "$var1,$var2 p"

解决方法是:

  • 不对shell变量使用单引号
  • 从sed命令中删除前导/
  • 使用管道代替命令替换

这篇关于使用sed提取行范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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