Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a file where the heading line is duplicated within the file, for example:
HEADING
11111
2222222
HEADING
333I need to delete all occurrences of the heading line after the first one, so that I am left with
HEADING
11111
2222222
333I can't seem to get it in sed. In vi/vim/ed/ex it would be
2,$g/^HEADING/d
i.e. from line 2 to the end of the file, find occurrences of ^HEADING and delete them. However this syntax is not valid in sed:
$ sed '2,$g/^HEADING/d' testit.dat
sed: -e expression #1, char 5: Extra characters after command
Any ideas? It doesn't have to be sed, but the file is almost 4GB so I think vi and ed are out unless there is an option I'm missing.
Thanks

It's not beautiful, but it works:
sed -e '2,$s/^HEADING$/non-existing-string/' -e '/^non-existing-string$/d' testit.dat
Luke Chi

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |