Web20 May 2015 · To delete 5 lines after a pattern (including the line with the pattern): sed -e '/pattern/,+5d' file.txt. To delete 5 lines after a pattern (excluding the line with the pattern): sed -e '/pattern/ {n;N;N;N;N;d}' file.txt. Share. Improve this answer. Web10 May 2024 · with GNU sed, to remove two lines before and three after the match (the values in the {} ). With general sed implementations, you don't have option -z, so you need …
Deleting a range of n lines before and after a matched line …
WebIf you have GNU sed (so non-embedded Linux or Cygwin): sed '/bar/,+1 d'. If you have bar on two consecutive lines, this will delete the second line without analyzing it. For example, if you have a 3-line file bar / bar / foo, the foo line will stay. Share. Web8 Feb 2024 · The sed command can be used to delete multiple lines matching a particular pattern. It is a powerful tool to quickly remove multiple lines matching a given pattern … barista k cups on sale
Delete all lines except first occurrence - HackerThink
Web25 May 2024 · How to Delete First and Last Line from a File. You can delete the first line from a file using the same syntax as described in the previous example. You have to put … Web30 Nov 2024 · How can I use sed to delete lines two (or any number) after a match but not including the match and lines in between? For example: Enter command below > login … Web19 Oct 2012 · In this example print second line: sed '2p' / etc /passwd. The ‘p’ command is preceded by a ‘2’. The number ‘2’ refers to line number two. You can tell sed to perform … suzuki bmi