Join David D. Levine for an in-depth discussion in this video Modifying the "s" command, part of SED Essential Training.
- By itself, the s command…affects only the first occurrence…of the initial string on each line.…You can add a g modifier, for global,…to the end of the command…in order to affect every occurrence on the line.…For example in this case,…we've added a g modifier…to our replacement of lowercase the with uppercase,…and so now it effects…every the on the line.…I'll clear the screen.…The g modifier looks for non-overlapping occurrences…of the initial string.…
For example, if we replace…aba…with --- , globally,…on every line in the standard input,…if we give it the input…ababababababa,…it only replaces some…of the aba's with dashes.…Now why is that?…The first substitution effects…the initial aba on the line,…which means the second aba,…beginning in position three,…is no longer there.…The next remaining aba…begins at position five, and so on.…
This non-overlapping behavior…can have unexpected consequences.…I'll clear the screen again.…For example, suppose you wanted to insert a hyphen…between every pair…of lowercase a's in the file.…
AuthorDavid D. Levine
- Understanding input, output, files, and pipes
- Modifying the "s" command
- Using character classes and quantifiers
- Controlling printing
- Reading and writing files
- Appending, inserting, and editing entire lines
- Writing programs in SED
- Using advanced programming commands
Skill Level Intermediate
1. Sed Command-Line Basics
2. Regular Expressions
Using & and \n5m 34s
3. Sed Command-Line Flags
4. More sed Commands
5. Writing Programs in sed
Exiting with "q" and "d"3m 5s
6. Advanced Programming Concepts
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.