【发布时间】:2020-04-29 18:47:15
【问题描述】:
我已经完成了这段代码来使用 sed 将特定行替换为特定行:
i=5
while (( i <= 10 ))
do
sed -i '$i s/.*/change/' file.txt
((i++))
done
这是文件.txt
1. alloha
2. this
3. is
4. just
5. a
6. test
7. nonsense
8. words
9. at
10. all
11. as
12. you
13. can
14. see
运行脚本后,file.txt 更改为:
1. alloha
2. this
3. is
4. just
5. a
6. test
7. nonsense
8. words
9. at
10. all
11. as
12. you
13. can
14. s/.*/change/
15. s/.*/change/
16. s/.*/change/
17. s/.*/change/
18. s/.*/change/
19. s/.*/change/
20. see
我相信 sed 命令可以正常工作,因为我在命令行中对其进行了测试,并且可以按我的意愿工作,我认为问题出在 i 变量上。
所以有人知道如何使它工作吗?
【问题讨论】:
标签: linux bash shell sed command-line