Just trying to delete lines of several .txt files – but keep getting SED error.

huangapple go评论42阅读模式
英文:

Just trying to delete lines of several .txt files - but keep getting SED error

问题

我目前正在尝试删除许多 .txt 文件的前 23 行。这是我目前正在做的:

sed -i -e 1,23d * .txt

但它给我一个奇怪的错误:

sed: 1: "1,23": command expected

我不知道该怎么办。

英文:

So, I am trying to delete the first 23 lines of many .txt files. This is what I am currently doing:

sed -i -e 1,23d * .txt

but it gives me a weird error:

sed: 1: "1,23": command expected

I have no idea what to do. _

答案1

得分: 2

像这样:

sed -i -e '1,23d' *.txt
#              ^    必须的 'd'
#                 ^
#       * 和 .txt 之间不要有空格
英文:

Like this:

sed -i -e '1,23d' *.txt
#              ^    mandatory 'd'
#                 ^
#       no space between * and .txt

答案2

得分: 0

以下是翻译好的部分:

原始问题(在编辑之前)显示:

sed -i -e 1,23d * .txt

但是给我一个奇怪的错误:

sed: Applications: in-place editing only works for regular files

“*”和“.txt”之间的空格是一个错误,但解释了奇怪的错误:它查找所有文件以及隐藏文件“.txt”。
Linux认为目录“Application”是一个文件,但“sed”不能在文件上工作。
目录“Application”暗示文件可能来自Windows。
另一个问题是为什么“echo *.txt”没有显示Mia所期望的txt文件。一个合乎逻辑的解释是这些文件起源于Windows,而Mia不知道Linux是区分大小写的。像“A.TXT”和“b.Txt”这样的文件不匹配“*.txt”。

当所有txt文件都以TXT结尾时,可以使用:

sed -i -e '1,23d' *.TXT

当你有大小写混合时,最简单的方法是:

sed -i -e '1,23d' *.[tT][xX][tT]

希望这对你有所帮助。

英文:

The original question (before editing) showed:

sed -i -e 1,23d * .txt

but it gives me a weird error:

sed: Applications: in-place editing only works for regular files

The space between * and .txt was a mistake, but is an explanation of the weird error: It looks for all files as well as for the hidden file .txt.
Linux considers the directory Application as a file, but sed does not work on files.
The directory Application suggests that the files might come from Windows.
Another question is why echo *.txt don't show the txt files Mia was expecting. A logical explanation is that the files originated from Windows and Mia doesn't know that Linux is case sensitive. Files like A.TXT and b.Txt don't match *.txt.

When all txt files end with TXT, you can do

sed -i -e '1,23d' *.TXT

When you have a mix of upper- and lower case, the easiest way is

sed -i -e '1,23d' *.[tT][xX][tT]

huangapple
  • 本文由 发表于 2023年2月14日 02:04:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定