Hi guys, long time no see ;-)
today when I was editing a new file using vi I decided that I need to find a pattern and then I wanted to perform some bulk editions on it.
1) open the file "vi file.txt"
2) find the pattern "/Streaming"
3) want to chop all text before this. this means to delete all previous lines before the line I am. I have google it a little bit... and found a method. Obviously that there are other optional ways to achieve the same result.
3.1) start by going to the previous line
3.2) Ctrl+G to find what is the current line number (eg. 567)
output: "file.txt" line 567 of 1180 --48%-- col 16
3.3) now we need to delete current line and previous 566 with ":.,-566d"
output: "Backwards range given, OK to swap (y/n)?" yes
3.4) voila, now the first line of the file is the line which has the first hit of the pattern "/Streaming"
hope this helps you!
helpful sources/references:
http://www.gammon.com.au/smaug/vi.htm#deleting
http://serverfault.com/questions/90294/search-and-delete-lines-matching-a-pattern-along-with-comments-in-previous-line-i
Subscribe to:
Post Comments (Atom)
1 comment:
you could also find the matching line, ctrl-G to get the line number, do the math, key :1 to get to the first line then key d d to delete lines.
easier to memorize
Post a Comment