Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个简短的文本文件,其语法如下:
FileName: some name Version: 3 Length: 45 hello, this is an irrelevant, unimportant text. So is this line.
现在,我正在尝试编写一个脚本,用给定的新号码替换版本号。
有谁知道怎么做?我真的不介意它丑
谢谢,乌迪
为什么不直接使用sed?
sed
sed -i 's/^Version: .*$/Version: 99/' foo.txt
我不知道如何在 csh 中做到这一点。然而,冒着被认为是那些告诉你在每一个机会使用他们最喜欢的东西的讨厌人之一的风险,有比使用 csh 更好的方法。传统的 unix 命令sed擅长这个东西,或者像 Perl 这样的语言也很有用。
perl -p -i -e 's/Version: 3/Version: 4/g;' myfile
应该这样做。