Text & Documentation / Search Text Files Using Regular Expressions pt. 2
Subtitles of the Movie
Exam objective 1.103.7 has a weight of 3, and verifies that candidates are able to manipulate files and text using regular expressions. This includes creating expressions containing several notational elements. It also includes using regular expressions to perform file edits. SED stands for Stream Editor. You can use it to modify text files. It normally is used in the script, but you can use it from the command line. It does several things, but basically it uses regular expressions to find things in the text and then has commands to modify what it finds. In the last two lines of this block of text the word 'people' occurs three times To show you how SED works, I will enter a command that will change those words. This is a substitution command. The S means substitute. The character following the S is the delimiter; in this example it's a slash. Between it and the next slash is a regular expression. It's used to find matches in the text. In this example, the search is for the letter P followed by any vowel, followed by another vowel, ending with another P. The string between the second two delimiters is the string used to replace the one matched by the regular expression. The G is a command to Globally apply the change. Normally SED will only change the first match it finds on a line, but global application is an instruction to change every occurrence on the line. This is the name of the input file. The output comes to Standard Out, so it will just be listed to the screen. Here's what happens. A reoccurrence of the word 'people' was found. The letter P followed by two vowels and another P and they were all changed to Stable. There is a lot more you can do with SED. You can insert entire lines, change lines, and so on, but the most common action is this simple replacement. You need to be aware of the types of things that SED can do. It's complex enough to be considered a programming language. The SED documentation will give you an idea of what can be done with it.
Tutorial Information
| Course: | Linux Professional Institute: Level 2 |
| Author: | Arthur Griffith |
| SKU: | 33894 |
| ISBN: | 1-934743-79-8 |
| Release Date: | 2008-07-21 |
| Duration: | 7.5 hrs / 113 lessons |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 70,000 Video Tutorials (14,250 free)
- Video Available as Flash or QuickTime
- Over 650 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 