1. 迭代文件中的每一行
- while 循环法
while read line;doecho $line;done < file.txt
改成子shell:
cat file.txt | (while read line;do echo $line;done)
- awk法:
cat file.txt| awk '{print}'
2.迭代一行中的每一个单词
for word in $line;doecho $word;done
3. 迭代每一个字符
${string:start_pos:num_of_chars}:从字符串中提取一个字符;(bash文本切片)
${#word}:返回变量word的长度
for((i=0;i<${#word};i++))doecho ${word:i:1);done
[URL=http://www.visitormap.org/][IMG]http://www.visitormap.org/map/m:bekbxjyftgtbwlff/s:1/c:ffffff/p:dot/y:0.png[/IMG][/URL]
No comments:
Post a Comment