Difference between revisions of "Piping and redirecting output from one command or file to another"

From CUC3
Jump to navigation Jump to search
import>Mp466
import>Mp466
Line 8: Line 8:
 
=== command line pipe ===
 
=== command line pipe ===
   
wc -l * | sort -rn
+
wc -l * | sort -rn
   
 
=== pipes in for loops ===
 
=== pipes in for loops ===

Revision as of 15:29, 4 July 2008

Piping entails sending standard output to the standard input of a linux command. Pipes are the primary power of using the command line. The can be used with sed, awk, perl, and python amoungst other tools to produce very specific behavior. To pipe the output to an new command place a '|' character between them.

Examples

command line pipe

wc -l * | sort -rn

pipes in for loops

 for f in `ls -al | awk '{print$9}' | sort`; 
 do 
    echo $f; 
    cp $f $f.bak; 
 done

names pipes