Save this video free

Lecture 11: tr command; Arrays

Burton Ma · 50:10 · Watch on YouTube

Part of Queen's University CISC220. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Burton Ma explains Bash’s `tr` command for character-by-character translation, deletion, and squeezing, then shows how Bash arrays work, including sparse indexes, safe expansion, iteration, concatenation, and input. The practical emphasis is avoiding silent array-reference mistakes and quoting variable expansions, especially filenames with spaces.

Key takeaways

Chapters

0:00 Using Bash `tr` for Character-by-Character Replacement
6:00 Character Ranges, Unequal Sets, and Duplicate Characters in `tr`
10:30 Deleting Characters and Squeezing Repeated Spaces with `tr`
15:00 Creating Bash Arrays and Accessing Sparse Integer Indexes
20:00 Avoiding Bash Array Dereference Mistakes and Declaring Arrays
25:00 Initializing Arrays and Counting Their Elements
30:00 Choosing Safe `[@]` and `[*]` Array Expansions
36:00 Iterating Over the Indexes Actually Used by an Array
39:00 Concatenating Bash Arrays and Appending One Element
42:00 Reading Input into Arrays and Quoting Filenames

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:02 Okay, good afternoon everybody. Uh so the two topics of today's lecture uh are something called the tr command um and arrays in bash. Oh so the tr command in bash is a you can think of it as being basically characterbased search and replace for strings. So you want to search a string for a character and replace it with another character. um or you want to delete particular characters from a string or you want to um remove duplicates or or sorry sequences uh repeated sequences of characters from a string. Uh tr is a command that you can consider using. Um it's also one of the commands that reads from standard input rather than reading from a file. Uh so typically in a script uh you're going to

0:50 need you'll use it in if you use it you'll use it in a pipeline, right? So generate some first use some command that generates some output. Pipe that output to the input of TR because TR is expecting its input from standard input. Okay. So the easiest way to learn how to use this is just to try it out. Um so let me first show you the simple example on the console and then we'll uh not that one. Sorry here. There we go. Okay. So tr so tr expects so in its first form or it's I guess it's uh the form that the default form um tr is in works in replacement mode. So here this says uh you would like to replace all instances

1:38 of the lowercase a with uppercase a. It's reading from standard input. So when I press return it's just going to wait and uh for me to type something in. Right? So I'm going to type in some string containing lowerase lowerase A

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.