日期:2014-05-16  浏览次数:20860 次

shell脚本提取文件中的字符串 急~~~
我有一个文件abc
里面内容如下:  
./5/9/4/20120627T145653_4feaaeb5000e1c0948b4ad04d27e5306.txt
./2/a/4/20120627T145602_4feaae820009ebba48b4ad04d27e5306.txt 
./4/1/f/20120627T155204_4feabba400051111803e210f45146c0d.txt 
./3/3/f/20120627T155251_4feabbd3000b7fa3803e210f45146c0d.txt内容都在一行当中的
去掉前面的小数点后将四个.txt依次取出放入数组中,因为后面要使用 网上找了各种资料都没找到答案
求各位牛人高手帮帮忙,小弟先谢过啦


------解决方案--------------------
小改一下:
C# code
[nicenight@CSDN ~]$ a=( $(sed -n 's/^.//;1h;1!H;$!b;$g;s/\n/ /g;p' abc.txt) )         
[nicenight@CSDN ~]$ for (( i = 0; i < ${#a[@]}; ++i )); do echo $i -- ${a[$i]}; done;
0 -- /5/9/4/20120627T145653_4feaaeb5000e1c0948b4ad04d27e5306.txt
1 -- /2/a/4/20120627T145602_4feaae820009ebba48b4ad04d27e5306.txt
2 -- /4/1/f/20120627T155204_4feabba400051111803e210f45146c0d.txt
3 -- /3/3/f/20120627T155251_4feabbd3000b7fa3803e210f45146c0d.txt

------解决方案--------------------
探讨

才把它真的搞定
请问下nicenight这两句具体是什么意思啊,shell接触不深
a=( $(sed -n 's/^.//;1h;1!H;$!b;$g;s/\n/ /g;p' abc.txt) ) 跟 ${#a[@]}
直接结贴就是给分是不哦? 小弟初次发帖 多多指教