Monday, April 14, 2014

Re: Select entire line based on tag, then export only those lines of text

Thank you very much for the help and suggestions. I am going to try to do this first thing today. I appreciate your time and assistance!
G


On Fri, Apr 11, 2014 at 3:13 PM, Tim Chase <vim@tim.thechases.com> wrote:
On 2014-04-11 07:37, Greg Nevius wrote:
> Hello everyone! First off, let me say that I am a designer, and
> don't have the higher level of thinking required to do what I would
> like to accomplish. That being said, if anyone could help me, I
> would be so, so grateful and appreciative!
>
> Here's what I've got - a tab delimited text file  ~1.6GB. It's a
> huge file.

This will be a dog to deal with.  If you have access to "sed", I'd
start by filtering the file down to just the matching lines and then
perform steps 2+ on those filtered results:

  sed -n /ambulance/ input.txt > ambulances.txt

If not, you might have a look at the "largefile" plugin

 http://vim.wikia.com/wiki/Faster_loading_of_large_files

which disables a few features that makes vim a *lot* faster when
dealing with huge files.  If you're doing this in vim, I'd copy the
file to one you can edit and then do the following:

  :v/ambulance/d

which will delete all the lines in the file that don't contain the
word "ambulance".  If you want to ignore case, you can use

  :v/ambulance\c/d

and if you want to keep the header lines, you can apply the command
to lines 2 through the end:

  :2,$v/ambulance\c/d

At this point, you should roughly have the same result as you would
have had with "sed", except that sed wouldn't suck up as much memory.

If you want to keep the header line in sed, you can use

  sed '2,$/header/d'

and if you want it to ignore case, at least with GNU sed, you can use

  sed '2,$/header/Id'

(On Win32, which you say you are, you might have to use double-quotes
around the command instead of single-quotes [include predictable
grouse about Win32 command-lines])

> Is this something that I can easily do in VIM? It seems like it's
> built for that.

Yep. :-)

-tim




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment