Home | Mirror | Search | 雜文 | ITEYE 博客 | OSChina 博客 | 51CTO 博客

4.9. Shell 技巧

4.9.1. 行轉列,再批評

echo "abc def gfh ijk"| sed "s:\ :\n:g" |grep -w gfh
            

4.9.2. for vs while

echo "aaa bbb ccc" > test.txt
echo "ddd eee fff" >> test.txt
            
for line in $(cat test.txt)
do
	echo $line
done
			
cat test.txt| while read line
do
	echo $line
done
			

4.9.3. 遍歷字元串

# find . -name "*.html" -o -name "*.php" -o -name '*.dwt' -printf "[%p] " -exec grep -c 'head' {} \; | grep -v "0$" |more
        	
comments powered by Disqus