bash sed 未终止地址正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22234430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sed unterminated address regex
提问by user3389814
I have a script that makes changes to various elements of a text file - it's a game setup and I need to change things based on the level the player chooses. Basically it takes one file, does some tidying up and then generates two start files for each level.
我有一个脚本可以更改文本文件的各种元素 - 这是一个游戏设置,我需要根据玩家选择的级别来更改内容。基本上它需要一个文件,进行一些整理,然后为每个级别生成两个起始文件。
This piece of code works fine but subsequent lines don't complete and I see messages regarding "sed: file scr line 4: unterminated address regex":-
这段代码工作正常,但后续行没有完成,我看到有关“sed:文件 scr 第 4 行:未终止的地址正则表达式”的消息:-
lines=`cat -n temp1 | grep TeamID= | grep -v TeamID=0 | awk '{print }'`
# Nothing to add for Noble / Prince
cp temp1 $noble_game_huts
echo "Creating Monarch"
# Monarch - adding TECH_ARCHERY
rm -f scr
for i in `echo $lines`
do
echo $i"a\" >> scr
echo "\tTech=TECH_ARCHERY
">> scr
done
sed -f scr temp1 > temp2
sed '0,/Handicap=HANDICAP_NOBLE/s/Handicap=HANDICAP_NOBLE/Handicap=HANDICAP_MONARCH/' temp2 > "$monarch_game_huts"
I've searched Google and this site but although there are a lot of hits nothing that seems to help here.
我已经搜索过谷歌和这个网站,但虽然有很多点击,但似乎没有任何帮助。
Running this script on Linux Mint 16 using bash.
使用 bash 在 Linux Mint 16 上运行此脚本。
Thanks.
谢谢。
Alan
艾伦
回答by NeronLeVelu
the lines extracted seems to have a line number corresponding to a team, each line read in i
then you want to add a text based on this line number.
提取的行似乎有一个行号对应一个团队,读入的每一行i
然后你想根据这个行号添加一个文本。
you need a space before the action a so i suggest
你需要在动作 a 之前留一个空格,所以我建议
echo "${i} a\\n\tTech=TECH_ARCHERY\n" >> scr
also (not for this problem)
也(不是针对这个问题)
lines=`sed -n '/TeamID=[^0]/ =' temp1`