【问题标题】:Substitution of ! with sed leads to event not found替换! sed 导致未找到事件
【发布时间】:2013-05-07 14:39:37
【问题描述】:

我需要将每次出现的! 更改为: 作为组文件中的字段分隔符。

sed 's/!/:/g' filename > newfilename 

但我收到错误 /: Event not found?

【问题讨论】:

  • 为我工作 (tm) $ echo 'this!is!a!test!line' | sed 's/!/:/g' this:is:a:test:line 你能更具体一点吗?
  • 我得到“/:找不到事件。

标签: sed csh tcsh


【解决方案1】:

您正在使用csh,因此! 被解释为修复此转义! 或仅使用bash

sed 's/\!/:/g' file > outfile

csh ! 用于命令历史记录引用,它甚至可以在一对撇号 ' 或引号 " 内使用,除非用反斜杠 \ 转义。

【讨论】:

  • 太棒了,我一定会注意这个例外。
【解决方案2】:

我可能会验证文件存在和文件权限,因为 sed 行工作正常:

[root@hacklab5 ~]# cat /tmp/sed.org 
dewed!Ddew!de
dewwe!ds!dewe
[root@hacklab5 ~]# sed 's/!/:/g' /tmp/sed.org 
dewed:Ddew:de
dewwe:ds:dewe
[root@hacklab5 ~]# sed 's/!/:/g' /tmp/sed.org > /tmp/sed.new
[root@hacklab5 ~]# cat /tmp/sed.new 
dewed:Ddew:de
dewwe:ds:dewe

【讨论】:

  • 我收到 /: 未找到事件
猜你喜欢
  • 1970-01-01
  • 2014-12-23
  • 2020-06-24
  • 2018-07-10
  • 2023-03-07
  • 2017-09-12
  • 2012-05-20
  • 2012-06-24
  • 2017-08-27
相关资源
最近更新 更多