Home | Mirror | Search

6. Shell 技巧

6.1. 行轉列,再批評

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

6.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
			

6.3. 遍歷字元串

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