我在sed中不断收到意外的令牌`/bin/busybox.exe'错误。我该如何解决?

时间:2019-05-20 00:28:13

标签: linux bash sed syntax busybox

我可以修改单个文件的标题和结尾,如下所示:

header1=randomstring,header2=0000
body body body
header1=randomerstring,header2=00000

使用以下命令:

sed "s/header1=.*header2=/header1=teststring1.teststring2.$(date +%d%m%Y)teststring3,header2=/" file

获得:

header1=teststring1.teststring2051919teststring3,header2=0000
body body body
header1=teststring1.teststring2051919teststring3,header2=00000

当我尝试使用for循环(请参见下文)将上述命令应用于具有相同前缀的多个文件时,我不断收到此错误:bash: syntax error near unexpected token `/bin/busybox.exe'。我怎样才能解决这个问题?同样,单个文件的命令会打印出文件内容,当我遍历文件时,我想删除此内容,但不确定要删除什么。

下面是产生错误的for循环命令:

for file in fileprefix.*; sed "s/header1=.*header2=/header1=teststring1.teststring2.$(date +%d%m%Y)teststring3,header2=/" i; done

同样,错误是bash: syntax error near unexpected token `/bin/busybox.exe'.

1 个答案:

答案 0 :(得分:1)

在循环中的“ sed”前面放置一个do,它应该可以工作;做和做只能成对出现。