Join David D. Levine for an in-depth discussion in this video Getting the next line with "n", part of SED Essential Training.
SED's n command simply prints out the current line…including any modifications made by previous commands,…and get's the next line from the input.…If you use the -n flag on the SED command line,…it supresses the printing action, and then the n command…just gets the next line.…Now this command may not seem very useful.…Until you consider that in a script, the commands…in a block, are executed in order for each matching line,…and by default the line is not printed until all…of the commands that apply to it have been executed.…
This means that the n command can be used within a block…to perform SED commands on lines after a given address.…Let me give you an example.…We'll cat into a script,…and we'll start off by matching lines…containing the word marched.…and when you find a match we'll do an n command.…Then we'll substitute…the beginning of the line with two parentheses.…
We'll do another n command, and then we'll…change the end of the line…to two parentheses.…Close the block.…End the script with control d.…So, the effect of this script is to put two…
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.