Results 1 to 9 of 9

Thread: Quick text-editing question

  1. #1
    Join Date
    Sep 2006
    Beans
    41

    Quick text-editing question

    I have a 15 GB XML file, and I want to find the line number of a specific line. I'm afraid to try to load it into any graphical text editor because it won't be able to load the entire thing into RAM.
    Is there a text editor or text viewer that will NOT attempt to load the entire file, but will still be able to give me a line number for the line, and let me see what's around it?

    Thanks in advance!
    -cvp

  2. #2
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Quick text-editing question

    Rather than using a text editor, if you just want to know the line number of a line and you know exactly what the line looks like, you could use grep instead:

    Code:
    grep -n "exactly what the line looks like" huge_file.xml
    That will print the line and the line number.
    Don't try to make something "fast" until you are able to quantify "slow".

  3. #3
    Join Date
    Sep 2006
    Beans
    41

    Re: Quick text-editing question

    Awesome, I have the line number now. Thanks!
    But is there another tool I can use to view the first dozen or so lines before that line and those after that doesn't attempt to load the entire file into RAM first?

  4. #4
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Quick text-editing question

    Grep to the rescue again!

    To print the 1 line before the match:

    Code:
    grep -B1 -n "exactly what the line looks like" huge_file.xml
    To print 5 lines after the match:
    Code:
    grep -A5 -n "exactly what the line looks like" huge_file.xml
    To print 10 lines before and after the match:
    Code:
    grep -C10 -n "exactly what the line looks like" huge_file.xml
    Hope that helps. If not, I'm not sure what editor to use but, hopefully someone else will.
    Don't try to make something "fast" until you are able to quantify "slow".

  5. #5
    Join Date
    Sep 2006
    Beans
    41

    Re: Quick text-editing question

    Sweet.
    Thank you so much!

  6. #6
    Join Date
    Sep 2006
    Beans
    41

    Re: Quick text-editing question

    Just for the record, the line I was looking for was line #256,453,718 out of 259,427,121 lines total.

  7. #7
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: Quick text-editing question

    If you have a line number you can also

    grep -n # huge_file.xml

    where # is the line number
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  8. #8
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Quick text-editing question

    Wow, it probably would have taken a while to find that by hand...

    If you are regularly working with xml files that large, you would probably find tools like grep, sed and perl very useful. There is a huge amount of information on the internet about these tools so, you should be able find good tutorials.
    Don't try to make something "fast" until you are able to quantify "slow".

  9. #9
    Join Date
    Sep 2006
    Beans
    41

    Re: Quick text-editing question

    Quote Originally Posted by vor
    If you are regularly working with xml files that large, you would probably find tools like grep, sed and perl very useful. There is a huge amount of information on the internet about these tools so, you should be able find good tutorials.
    Oh, definitely. I'm a research intern, and most of my job is teaching myself Perl as I go. I could've written a simple Perl script to do all of this, but I figured there was some easier way with shell commands, and lo and behold, there were and probably are several other ways to go about it.
    I love being paid to learn.

    Anyway, thanks again!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •