Quoting command-line arguments

The SED command that we've been using so far,…sed s/the/THE/ doesn't need to be quoted.…For example, if you omit the quotes like this,…it works exactly the same as it did before,…but quoting SED's command argument…is a very good habit to get into.…Quotes are needed in case the command contains a space…or a character that is special to the shell.…For example, (keyboard clicks)…sed 's/the/…some of the/' dukeofyork.txt.…

This example changes the first "the" in each line…to "some of the," but if you omit those quotes,…it doesn't work.…It fails with an error.…Here's another example.…We can change thousand (keyboard clicks)…to $1000.…(keyboard clicks)…This changes ten thousand men to ten $1000 men.…But if you omit the quotes,…(keyboard clicks)…it changes those $1000 men to 000 men…because the $1 was replaced…with the value of the variable 1,…which is the first argument of the shell itself,…which for a login shell is an empty string.…

Note, though, that if you get into the habit…of using single quotes, apostrophes can bite you.…

Resume Transcript Auto-Scroll

Author

Released

6/10/2015

SED is the one of the original command line tools for parsing and transforming data on Unix, Linux, and Macintosh machines. David D. Levine helps you unlock the power of SED's compact syntax in these lessons, which cover extracting, transforming, and manipulating data in files and data streams. He reviews the basic commands, including one you'll never want to forget, and shows how to work with regular expressions. The course also covers SED's more advanced programming features, which allow you to write simple programs and manage multiline pattern space, flow, and the hold buffer with a few simple keystrokes. Start here to learn the essentials of this versatile tool.