Sed

  • What is Sed?
    • Sed is a stream editor
    • Most popular use is substitutions
    • Sed can support Regular Expressions (regex)
    • Sed is considered non-destructive, that means be default it doesn't change the original file
  • What is Sed good at?
    • Substitutions
    • Seeing what a file can look like without damaging the original
  • What is Sed not so good at?
    • Sorting the file
    • Easy to understand error messages, it's also not as well documented as it could be
  • Some examples of how to use sed as shown in the video
    • sed s/originalTerm/NewTerm/ filename
    • You can also put the results in a file if you don't want to show them on screen only using append (>>) and Redirect (>) sed s/originalTerm/NewTerm/ filename >> newFileWithChanges
    • sed
    • To have a global substitution instead of first instance only, you add the g at the end "sed s/o/0/g filename"
    • We can make sed print lines matching the pattern instead of substitutions by doing "sed -n '/MA/ p' filename"
    • We can have multiple instances of sed as well by doing something like "sed s/0/o/g filename | sed s/3/s/g"
  • Some Sed Resources

Suggested Activities and Exercises:

  • Download the sedLab File by right clicking Hereand saving your file onto your Linux machine, and then Complete the problem sets that are found on This PDF using the sedlab file you downloaded from above. Make sure you are paying attention to file location and your paths

Would you like to see some more classes? Click here