Page 1 of 4 1234 LastLast
Results 1 to 15 of 56
  1. #1
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default Help with macros and Java

    I'm editing a very large text file in OpenOffice (7,000+ pages, over 420,000 lines) and I've been able to use Search and Replace for a lot of the editing.
    However I'm now at the stage that the find part of the equation works but there is no way to do the replace.
    What I have to do is search for a particular character which is the first character in a line, for example the number 1.
    I then have to go to the end of the line above and hit delete to bring all the text in the lower line into the line above it.

    ACROBAT CREEK QLD,Stream,,-26.70000,152.97000
    Acron Oval NSW,Reserve,,-33.73000,
    151.17000
    Acrostic Ridge NSW,Ridge,,-32.54000,150.19000
    Actaeon Island Game Reserve TAS,Reserve,,-43.52000,146.99000


    This is a database of Australian place names and various locations.
    I am reverse engineering the database so that I can add new locations to it and then compile it so it runs on my Hema navigator.




    I have recorded the macro, but when I try to run it I get the following message:
    "Openoffice requires a Java runtime environment (JRE) to perform this task. Please
    insall a JRE and restart OpenOffice"


    I downloaded jre-8u65-windows-x64.exe and ran it, I restarted my computer and opened the document in OpenOffice, but I still can't get the macro to run.

    Any help would be greatly appreciated.
    Last edited by Grumpy John; 26th December 2016 at 06:47 PM. Reason: Added additional information
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  2. # ADS
    Google Adsense Advertisement
    Join Date
    Always
    Location
    Advertising world
    Age
    2010
    Posts
    Many





     
  3. #2
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    If you download Notepad++ or PFE32 the job will be faster. These are pure text editors.

    Your find replace strings are "\n1" with " 1"

    i.e. replace newline 1 with space 1

    It will rip through the file in milliseconds.

  4. #3
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    I have Notepad++, but the file is o large it hangs when loading.

    Okay, I just tried it again and it opened in a flash. I have reduced the file from 53Meg down to 17Meg, just by removing all the unnecessary spaces.
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  5. #4
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    So if I wanted to find all instances of N/A and delete the whole line including the return at the end of the line how would I do it?
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  6. #5
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    If you need a hand, just ask. I did this as a job processing and munging giant files and stuffing them into databases. Clients would hand us the most aweful crap. Government was the worst. They were utterly, completely and totally clueless.

    I often wrote brief programs to handle the really nasty stuff. Often in perl and PHP using grep and such.

  7. #6
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    Quote Originally Posted by Grumpy John View Post
    So if I wanted to find all instances of N/A and delete the whole line including the return at the end of the line how would I do it?
    If its litterally "N/A" the search replace would be "N/A\n" with ""

    i.e. in English: find N/A and newline character, then replace all of it with nothing.

  8. #7
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    Thanks Wood Pixel. I actually recorded a macro and played it to the EOF and that did the job.
    I've got heaps more to do, so I may have more questions.
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  9. #8
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    Quote Originally Posted by woodPixel View Post
    If its litterally "N/A" the search replace would be "N/A\n" with ""

    i.e. in English: find N/A and newline character, then replace all of it with nothing.
    Should I have match Whole Word Only and Match Case checked?
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  10. #9
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    Notepad++ is an absurdly powerful little program. You can do some very gnarly things with a thing called Regex .... regular expressions.

    A quick google on "Notepad++ find and replace" has a few blogs that describe various aspects, but this one seems to cover things off Mark's Speechblog: Notepad++: A guide to using regular expressions and extended search mode

    F2 and F3 are your friends. Remember to save incrementally often, it will make it faster, plus give you something to go back to when you explode it.

  11. #10
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    Damn it's fast,

    Next question:
    Find all occurrences of a space at the start of a line. Then cut and paste that line (including space) into the line above.
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  12. #11
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    Quote Originally Posted by Grumpy John View Post
    Should I have match Whole Word Only and Match Case checked?
    Probably not. If you are searching for a specific thing then these might help. For example finding the word "boo" will also find Boo, boogle and booble. These options simply help with either finding or eliminating these finds.

    For this stuff it's often a case of "try and see if it works"!!!

    Data is generally a mess and there are a billion rules and tricks, but like most things knowing just a few covers 98% of cases. Just remember to save incrementally so you can roll it back. I.e. call the file text2.txt or text3.txt etc.

  13. #12
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    Quote Originally Posted by Grumpy John View Post
    Find all occurrences of a space at the start of a line. Then cut and paste that line (including space) into the line above.
    Find "\n " replace " "

    I.e find newline character then space, replace with just space

    One thing to think of when looking at text and how it's laid out is the machine litterally sees it as one single giant line. It is presented to us with line breaks, character returns and other odd characters that may turn up, such as \0x

    These are normally invisible. Just prune them as needed.

  14. #13
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    Quote Originally Posted by woodPixel View Post
    Find "\n " replace " "

    I.e find newline character then space, replace with just space

    One thing to think of when looking at text and how it's laid out is the machine litterally sees it as one single giant line. It is presented to us with line breaks, character returns and other odd characters that may turn up, such as \0x

    These are normally invisible. Just prune them as needed.
    That instruction is just adding a space to the start of the line i.e. line #656 starts with a space, I need that entire line moved to the end of line #655.

    Your help is greatly appreciated.
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

  15. #14
    Join Date
    Feb 2016
    Location
    Canberra
    Posts
    5,124

    Default

    Quote Originally Posted by Grumpy John View Post
    That instruction is just adding a space to the start of the line i.e. line #656 starts with a space, I need that entire line moved to the end of line #655.
    My pleasure to assist. no need for thanks.

    You will find there is a hidden character by windows there called \r

    It is the Return line character.

    Try this: find " \r\n" replace " "

    English: find space windowsReturn newline, with just space

    Edit: try " \r" replace " " just in case the offending character is only the \r

    The link I gave above is very good indeed. I took the time to give it a bit of a read and must say the guy has done a service to the Internet to publish it

  16. #15
    Join Date
    Aug 2005
    Location
    Cranbourne West
    Age
    72
    Posts
    3,612

    Default

    I ended up creating a macro using the "\n " and going to the end of the line above and hitting delete.
    Ran the macro till the EOF, worked like a charm.
    To grow old is inevitable.... To grow up is optional

    Confidence, the feeling you have before you fully understand the situation.

    What could possibly go wrong.

Page 1 of 4 1234 LastLast

Similar Threads

  1. Micro-Macros
    By Ed Reiss in forum PHOTOGRAPHY
    Replies: 0
    Last Post: 3rd February 2013, 01:49 PM
  2. New Macros
    By Ed Reiss in forum PHOTOGRAPHY
    Replies: 4
    Last Post: 10th November 2011, 08:08 AM

Posting Permissions

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