sp25-cs400 cs400
Streams and Pipes Streams and Pipes
Redirection
The < and > operators are used to redirect input and output in the terminal.
<is used to redirect input from a file to a command.>is used to redirect output from a command to a file.
# Redirecting input from a file
cat < input.txt
# Redirecting output to a file
echo "Hello, World!" > output.txt
# Redirecting both input and output
cat < input.txt > output.txt
Pipes
Pipes are used to connect the output of one command to the input of another command. The | operator is used to create a pipe.
# Using pipes to connect commands
cat input.txt | grep "pattern" | sort
The above command reads the contents of input.txt, filters lines containing “pattern” using grep, and then sorts the filtered lines using sort.
Connections
Obvious technical and formatting errors repaired.