csh/python/tcl常用功能小总结
Csh
逐行读取并处理文本
代码一
1 #!/bin/csh
2 set n=`wc -l <session.dat`
3 set i=1
4 while ($i <= $n)
5 set line="`awk '{if (NR == $i) print}' data.dat`"
6 echo "${line}"
7 @ i ++
8 end
代码二
1 #!/bin/csh
2 foreach line (`awk '{print}' data.dat`)
3 echo "${line}"
4 end
其中代码一为完美做法;
代码二只适用于文件行中没有空格的情况,否则foreach会识别为多个元素。
if语句及字符串的匹配
1 if ("${line}" =~ *VDD* ) then
2 sed -i "/VDD_NETS/a\${line}" conf/${analogCell}.conf
3 endif
Python
Python逐行读取文件内容的三种方法
https://blog.youkuaiyun.com/zhengxiangwen/article/details/55148287
使用while readline
f = open("foo.txt") # 返回一个文件对象
line = f.readline(