Saturday, January 5, 2013

UNIX pipes and redirects

The Unix Command Line: Pipes and Redirects ... tr, sort, uniq, comm 으로 사용한 예
 tr 'A-Z' 'a-z' <fnord.txt | tr -cs 'a-z' '\n' | sort | uniq | comm -23 - /usr/share/dict/words  

Pipes and Filters ... cat, wc, sed, awk, grep 으로 사용한 예
 $ cat apple.txt  
 core  
 worm seed  
 jewel  
 $ cat apple.txt | sed -e "s/e/WWW/"  
 corWWW  
 worm sWWWed  
 jWWWwel  
 $ cat apple.txt | sed -e "s/e/J/g"  
 corJ  
 worm sJJd  
 jJwJl  
 $ cat basket.txt  
 Layer1 = cloth  
 Layer2 = strawberries  
 Layer3 = fish  
 Layer4 = chocolate  
 Layer5 = punch cards  
 $ cat basket.txt | awk -F= '{print $1}'  
 Layer1  
 Layer2  
 Layer3  
 Layer4  
 Layer5            
 $ cat basket.txt | awk -F= '{print "HAS: " $2}'  
 HAS: cloth  
 HAS: strawberries  
 HAS: fish  
 HAS: chocolate  
 HAS: punch cards      

Unix - Pipes and Filters ... ls, grep, sort 로 사용한 예
 $ls -l | grep "Aug"  
 -rw-rw-rw-  1 john doc   11008 Aug 6 14:10 ch02  
 -rw-rw-rw-  1 john doc   8515 Aug 6 15:30 ch07  
 -rw-rw-r--  1 john doc   2488 Aug 15 10:51 intro  
 -rw-rw-r--  1 carol doc   1605 Aug 23 07:35 macros  
 $ls -l | grep "Aug" | sort +4n  
 -rw-rw-r-- 1 carol doc   1605 Aug 23 07:35 macros  
 -rw-rw-r-- 1 john doc   2488 Aug 15 10:51 intro  
 -rw-rw-rw- 1 john doc   8515 Aug 6 15:30 ch07  
 -rw-rw-rw- 1 john doc   11008 Aug 6 14:10 ch02  

No comments:

Post a Comment