sed - 在 tcl 文件中使用 sed
问题描述
嗨,我是新的 tcl,遇到了如下问题。
在这段代码中,我试图从文件中只获取第 1 行和第 2 行,并希望将它们放入另一个变量中。但是这段代码对我不起作用。
set sed_com "${line1},${line2}p"; # the value of this sed command is 1,2p
set tmp [exec sh -c {sed -n "${sed_com}" file.tmp | tail -n 1}]; # this one won't work
set tmp [exec sh -c {sed -n "1,2p" file.tmp | tail -n 1}]; # this one will work
我想知道是否有一种方法可以让 tcl 文件像第 3 行一样解释它?
解决方案
你为什么把事情复杂化sh -c
?你可以这样做:
set tmp [exec sed -n $sed_com file.tmp | tail -n 1]
推荐阅读
- jms - JBoss EAP 7.1 中的 JMS 桥接器没有将消息推送到目的地
- c++ - 如何在我的头文件中包含 pcl 而不抛出“没有这样的文件或目录错误”?
- django - 可以使用 Auth0 JWT 令牌向 Django 后端发送 POST 请求吗?
- c# - 如果在“等待”之后抛出,则从任务中抛出的异常被吞没
- .net - 从 Getter 中调用属性 Setter 不会执行 Setter?
- php - 如何通过传入 ID 更改数组中的字段值
- git - 恢复 git 重置
- class - 如何定义一个类,其中某些边缘对于 OrientDB 中的所有分配记录都是强制性的?
- terraform - 无法再创建/销毁 Azure VM (OSProvisioningInternalError)
- javascript - 如何将数据从 Flask 传递到 Javascript?