返回列表 发帖

[问题求助] Shell脚本 for 循环中变量无法在sed命令中使用?

如下代码
for  i  in  `cat file_list.txt`
do
echo $i
sed -n -e '/Copyright/=' $i
doneCOPY
查找file_list.txt记录文件中的copyright字样在第几行。执行结果如下:
inc/os/mtos_int1.h
: No such file or directory_int1.h
inc/os/mtos_task.h
: No such file or directory_task.h
inc/kware/record/record_seq.h
: No such file or directoryecord/record_seq.hCOPY
求教:为什么变量$i可以正常输出,但无法在sed中使用。

如果你的 file_list.txt 是从 Windows 复制到 Linux 里面的,需要先把它转换格式,执行命令:
dos2unix file_list.txtCOPY
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 2# Batcher


    这个可以保证的。 echo $i 可以正常输出

TOP

sorry,又检查了一遍,确实为dos格式的。  
文件新建是在linux上建的,可能是在samba里面查看的时候不小心转成了dos了

TOP

回复 4# xdahoufang


    用 cat -A file_list.txt 可以很方便的确认格式
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

学习了,,,刚安装了个dos2unix,,确实很好用。
问题解决后,请在标题前面注明[已解决],并给回答者加分——化繁为简,提高工作效率!

TOP

返回列表