Sometimes, magic one-liners are insufficient for manipulating data. Loops and conditionals enable us to iterate over data in interesting ways without sticking to default behavior.
Bash views non-binary files and streams as collections of characters. We commonly think of these characters as groups of strings separated by some kind of whitespace. It makes sense that some of the most useful and common tools in the command-line universe are the ones that search and manipulate these strings.
The following topics will be covered in this chapter:
- for loops
- while loops
- File test conditionals
- Numeric comparisons
- String case statements
- Using regular expressions and grep to search and filter
- String transformations using awk, sed, and tr
- Sorting lists of strings with sort and uniq
Along the way, we'll see how we can pipe the results of one program...