如何在SED中编辑多行
我有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.
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 tokensed' bash: syntax error near unexpected token
done'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要聪明很多
这样做的事情首先
,您忘记了 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
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.