Getting ready

Let's get ready for the exercise by creating some data sets which mimic common daily problems:

$ rm -rf testdata; mkdir -p testdata$ echo "Bob, Jane, Naz, Sue, Max, Tom$" > testdata/garbage.csv $ echo "Zero, Alpha, Beta, Gama, Delta, Foxtrot#" >> testdata/garbage.csv $ echo "1000,Bob,Green,Dec,1,1967" > testdata/employees.csv$ echo "2000,Ron,Brash,Jan,20,1987" >> testdata/employees.csv$ echo "3000,James,Fairview,Jul,15,1992" >> testdata/employees.csv

Using these two CSVs, we are going to:

  • Remove the extra spaces on the first two lines of garbage.csv
  • Remove the last character from each line in garbage.csv
  • Change the case of each character to uppercase in the first two lines of garbage.csv
  • Replace Bob with Robert in employees.csv ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.