# Streams and Pipes

Source: https://wisconsin.twango.dev/sp25-cs400/topics/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.

```bash
# 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.

```bash
# 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

- [[sp25-cs400/topics/index|Topic index]]

Obvious technical and formatting errors repaired.
