如何在SED中编辑多行

发布于 2025-02-04 13:41:41 字数 819 浏览 2 评论 0原文

我有45行代码需要SED命令。由于GNU最近发生了变化,我所有的脚本都在破坏,需要-STD = legacy& - 堕落的活节。我知道该怎么做的唯一方法是使用SED。我不是计算机程序员,SED简单易懂。

这些是我的SED命令的示例。

有没有办法在循环或SED本身中执行所有这些SED命令。如果还有另一个编辑器使我也可以尝试学习这一点。

我已经尝试过,

for X in [24,28,32,36,40,45,49,53,56,60,64,68,69,73,74,79]
    sed -i '$Xs/= /= -std=legacy -fallow-invalid-boz /g' $HOME/WRF/Downloads/NCEPlibs/macros.make.linux.gnu
done

但是我遇到了错误:

$ x in [24,28,32,36,40,45,49,53,56,56,60,64,68,68,69,73,74,79] sed -i '$ XS /= /= -STD =旧版-Fallow -Invalid -boz /g' $ home/wrf/downloads/nceplibs/macros.make.linux.gnu完成bash:语法 靠近意外令牌的错误

I have 45 lines of code that need a sed command. Due to the recent change in GNU all my scripts are breaking and need -std=legacy & -fallow-invalid-boz. The only way I know how to do this is with sed. I'm not a computer programmer and sed is simple and easy to understand.

These are a sample of my sed commands.

enter image description here

Is there a way to do all these sed commands in a loop or with sed itself. If there is another editor that makes it easier I can try to learn that too.

I have tried this

for X in [24,28,32,36,40,45,49,53,56,60,64,68,69,73,74,79]
    sed -i '$Xs/= /= -std=legacy -fallow-invalid-boz /g' $HOME/WRF/Downloads/NCEPlibs/macros.make.linux.gnu
done

But I get the error:

$ for X in [24,28,32,36,40,45,49,53,56,60,64,68,69,73,74,79] sed -i
'$Xs/= /= -std=legacy -fallow-invalid-boz /g'
$HOME/WRF/Downloads/NCEPlibs/macros.make.linux.gnu done bash: syntax
error near unexpected token sed' bash: syntax error near unexpected tokendone'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

星光不落少年眉 2025-02-11 13:41:41

要聪明很多

y="24 28 32 36 40 45 49 53 56 60 64 68 69 73 74 79"
for X in $y; do
  sed -i "${X}s/= /= -std=legacy -fallow-invalid-boz /g" $HOME/WRF/Downloads/NCEPlibs/macros.make.linux.gnu
done

这样做的事情首先

,您忘记了 do 中,因此for语句甚至可以在执行之前就会失败。第二[24,28,32,36,40,45,49,53,56,56,60,64,64,68,68,69,73,74,79]无效或白色空间来声明从左到右的新值。

最后但并非最不重要的一点是,在此示例中,使用 $ x 是无效的,因为bash将其读为 $ xs/,因此使用 $ {x} 是正确的方法,当然可以使用“” 而不是使用'' SO $ {x} 实际上可以使用。

doing it like this is a lot smarter

y="24 28 32 36 40 45 49 53 56 60 64 68 69 73 74 79"
for X in $y; do
  sed -i "${X}s/= /= -std=legacy -fallow-invalid-boz /g" $HOME/WRF/Downloads/NCEPlibs/macros.make.linux.gnu
done

First of all, you forgot the do statement in for so the for statement will just fail before it can even execute.

Second of all [24,28,32,36,40,45,49,53,56,60,64,68,69,73,74,79] in not valid as for uses newlines and or white spaces to declare a new value going from left to right.

And last but not least, using $X is not valid in this example as bash reads it as $Xs/ so using ${X} is the correct way and of course using "" instead of using '' so ${X} can actually be used.

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