sed 中的版权字符

发布于 2024-11-18 14:14:18 字数 366 浏览 4 评论 0原文

我试图删除包含版权字符的所有行(除其他外,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无可置疑 2024-11-25 14:14:18

您可以尝试使用 © 的八进制表示形式,即 251

$ echo blah © blah | sed 's/\o251/X/'
blah  blah

它位于“oh”而不是零。

要删除包含该字符的行,请使用

sed '/\o251/d'

You might try using the octal representation of © which is 251

$ echo blah © blah | sed 's/\o251/X/'
blah  blah

That is on "oh" and not a zero.

To delete lines containing that character, use

sed '/\o251/d'
我的影子我的梦 2024-11-25 14:14:18

sed 命令看起来不正确。尝试

sed '/©/d'

并检查在运行脚本的 shell 中是否设置了适当的区域设置环境变量。例如,我使用

LC_ALL=en_US.UTF-8

The sed command doesn’t look right. Try

sed '/©/d'

And check that the appropriate locale environment variable set in the shell in which the script runs. For example, I use

LC_ALL=en_US.UTF-8
生生漫 2024-11-25 14:14:18

尝试使用 grep 代替

grep -v '©'

try using grep instead

grep -v '©'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文