Join David D. Levine for an in-depth discussion in this video Solution: Write the main() function from array.c to file main.c, part of SED Essential Training.
- The challenge is to take the file…array.c, which is a c program,…and extract from it the main function…writing that to the file main.c.…The main function you can see here begins with…int main (void)…and extends to the closing brace…near the bottom of the screen.…So here's one possible solution.…We won't want to print anything to the screen.…What we do want to do is…from a line containing the word main,…to the following line beginning with…a closing brace, we'll write…to the file main.c.…
And apply that to array.c.…Did it work?…Yes, it did, it wrote the entire main function…from its opening declaration to its closing brace…to the file main.c.…Now, this solution depends on the fact…that the word main only appears once in the file.…Here's a more robust version.…From any line beginning with…a lowercase letter or any number of lowercase letters,…and then a space, main,…and then any number of spaces,…opening parenthesis, to…a line beginning with, a closing brace,…write to main.c, array.c.…
So again, this ones looks for a line…
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.