sed 中的版权字符
我试图删除包含版权字符的所有行(除其他外,在 bash 脚本中),但它根本不起作用:
cat $srcdir/$txtfile |
sed "s/.*©.*/d" |
cat > $tgtdir/$txtfile
什么也不做。但是,
echo blah © blah | sed "s/.*©.*//g"
在终端中正确运行会导致
blah blah
我使用设置为 UTF-8 编码的 SciTE,因此上面的第一段代码正是我在编辑器中看到的内容。关于如何在编辑器中表示它以便 sed 能够识别它有什么想法吗?
I'm trying to remove all lines containing the copyright character (among other things, in a bash script), but it's not working at all:
cat $srcdir/$txtfile |
sed "s/.*©.*/d" |
cat > $tgtdir/$txtfile
does nothing. However, running
echo blah © blah | sed "s/.*©.*//g"
in the terminal correctly yields
blah blah
I'm using SciTE set to UTF-8 encoding, so the first block of code above is exactly what I see in the editor. Any ideas on how I could represent it in an editor so sed will recognise it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用 © 的八进制表示形式,即
251
,它位于“oh”而不是零。
要删除包含该字符的行,请使用
You might try using the octal representation of © which is
251
That is on "oh" and not a zero.
To delete lines containing that character, use
sed 命令看起来不正确。尝试
并检查在运行脚本的 shell 中是否设置了适当的区域设置环境变量。例如,我使用
The sed command doesn’t look right. Try
And check that the appropriate locale environment variable set in the shell in which the script runs. For example, I use
尝试使用
grep
代替try using
grep
instead