[SOLVED] Sed -n '/pattern/{n;p;}' is missing matches in file
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Following your suggestion, I went back and added line numbers, now the output is:
2 Turn
4 H310
6 Turn
10 Turn
while I expect:
2 Turn
3 Turn
4 H310
6 Turn
7 Alpha
10 Turn
Which matches what I thought was happening, that sed is identifying matches, advancing to the next line and printing, but after advancing is not checking to see if the line it advanced to matches the pattern. Any ideas on how to get my desired result?
Not sure on getting the desired result but you are aware that the n;p says get the next line and print it.
Sed cannot then say I need to check the next line as well (not as written).
Now I am guessing one of the gurus will have this a better way, but the following seems to work:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.