Searching for a particular string in 5000+ text files. - java

I solve bugs for a product. The customer has sent a bundle of log files. I am required to search for a particular string in these log files. The number of log files is more than five thousand.
I cannot use grep because I am working on a windows machine.
What are my options here ? I was thinking about writing a program in java where I open every text file in a directory and search for a particular pattern. But I could not find a api where i can open every file one after the other.
Can you please suggest me a solution. I can also code in C++ or C# is somehow a solution can be built there.

I would suggest installing Cygwin and using grep

If you need to do this only manually, then just install any decent editor (my suggestion would be http://notepad-plus-plus.org/), and use its find-in-files function.

How about using findstr command from command prompt.

Perl. It takes about three lines of code to search every file in a directory for a string. You can learn enough Perl to do that in half an hour.

This works in Windows XP. I don't know about the more current versions.
Click on the Windows Start Button
Click on Search
A new window will open. On the bottom left, click on "Click here to use Windows Search Companion"
Another window will open.
In the text box labeled "A word or phrase in the file" type in what you're looking for.
In the combobox labeled "Look in", at the very bottom, select "browse..." and select the folder with all the log files.
Click "Search"
Wait for the results...
Note: there are 2 search programs. The first one only finds things that have been indexed, which is why you should use the second search program instead.
Good luck!

Consider VIM editor which is awesome when working with huge files. You can use it under Cygwin, and you can use on Windows. Use cheat sheets to learn it quickly.

Related

Open PDF to a specific page

Is there a way to go to open a specific PDF-page with Java?
It can either open the page in Adobe Reader or a built in reader in Java.
I have the file path and the file saved locally.
It looks like you have a couple of options here.
The easiest way to do this on Windows would be using the command line. Both Acrobat and Reader take command line arguments such as zoom level and starting page. The command to open a document on a specific page on Windows looks like this:
Acrobat.exe /A "page=1000" "C:\example.pdf"
And here is a reference of all the parameters Acrobat and Reader take on Windows - Parameters for Opening PDF Files.
On Mac, things get a bit tricky. Neither Acrobat nor Reader take command line parameters there. However, you still have some options on the Mac. Your best option would be to use AppleScript. Acrobat has extensive support for it, it's fairly easy to get started, and you can even import the AcrobatLibrary and see a list of available API. Here is a good article to get you started on this. As with Windows, it looks like this is both available for Acrobat and Reader.
I've put together a small script that should open a document and then go to a specific page.
tell application "Adobe Acrobat Pro"
tell PDF Window 1
goto page 3
end tell
end tell
Here is a good way to open the newly created AppleScript from Java.
You can add a "go-to" PDF action to the document's "open" viewer application event. Here is how you do it with our company product PDFOne (for Java). You might be able to do the same with other PDF libraries.
http://www.gnostice.com/nl_article.asp?id=217&t=Trouble_free_Linking_To_PDF_Pages_Online
Sample PDF: http://www.gnostice.com/newsletters/downloads/2011_03/PDF_that_skips_to_page_3_by_default.pdf
I think this is what you are asking for...
Say you have a document that has several pages of minutia at the beginning (perhaps a bunch of legalese that you’re not going to read the first time, much less every time). Rather than scrolling past all that minutia every time, you want it to go straight to the table of contents so you can find what you’re looking for more quickly.
If that sounds similar to what you are wanting, then here you go…
(By the way, I’m using Adobe Acrobat Pro. I don’t know if this will work for Reader.)
Open the document in Adobe.
Click Enable All Features.
Click File.
Click Properties.
Click on the tab called Initial View.
Find where it says “Open to page” and enter the page number you want it to open to.
Click OK.
Save the file.
Close the file.
Reopen the file. (It should open to the page you set.)

How to create a dashboard using excel and .bat file

I would like to ask the community if there is any way to create a GUI menu where the options will populate itself based on number of files that are saved in a folder directory. The user will then have two options whereby he can choose to generate a status or a dashboard option. After he chooses the report that he wish to generate, another menu will appear to ask him which document he want to select. This is where the menu would check the folder and generate the options based on number of files in the folder. For example, there could be doc1 and doc2 in the folder. Then the menu will generate 2 options. 1. Select doc1. 2. Select doc2. Then after the user inserted another doc3 into the folder. The menu will add another 3. Select doc3 without having the user to change the code. Is there a way to do this? Thanks.
This makes no sense. A .bat file is by definition something that does not have a GUI.
Also you really have provided the vaguest information for something seemingly large, and there appears to be no reason why you've also tagged this as excel and exe.
Since your .bat file could launch a particular Excel file, you could go that way, putting all the dashboard info in the spreadsheet. Would require some VBA code to make it as interactive as it sounds like you want, but that's entirely possible.
I'm not aware of any way that a .bat file can create a GUI on its own, although I may be missing something. Since the .bat file can run almost anything, it can be a starting point, but the heavy lifting would be done in something else.
Another approach would be to look at AutoHotkey, which can give you a GUI and a fair bit of processing power & interactivity all within the one script. The URL is http://www.autohotkey.com/ and that site has a tremendous amount of examples and help available. Also some AHK questions here on Stack Overflow from time to time.
Either way you go, it's a fairly large project. Good luck!

Create Windows Symbolic Link with Java (equivalent to MKLINK)

Could anyone please tell me how to make a symbolic link (in the same way MKLINK does) and/or remove a symbolic link with Java. I have found solutions that use Java as a wrapper and use a Windows native program to accomplish this, but I really want a pure Java solution. Thank you in advance!
Since Java 7 you can do this easily using the NIO package.
Path target = Paths.get("target");
Path link = Paths.get("link");
Files.createDirectory(target);
Files.createSymbolicLink(link, target);
Do remember that you do need the correct privileges for this. In my unit test I had to run eclipse as an administrator to make it work (same as that I couldn't create a link from a normal cmd.exe)
As far as I know window does not have real symbolic links like Unix-like system do.
However Windows has the following relevant tools:
You can map network drive, i.e. attach drive letter to specified network path. You can definitely do this using WMI. To access WMI from java take a look on tools like JaWin, Jinterop, Jintegra or write WMI script in JScript o VBScript and execute is from Java.
You can use command subst that assigns letter to local file system path. This is the closest approach to Unix soft link.
You can create desktop shortcut. Create one manually and take a look on it. Shortcut is actually regular text file (as far as I remember in INI format). You can easily create one using any language you want including java. This is not soft link but it is clickable.

Convert DGN to PDF

How can I convert MicroStation (DGN) files to PDF via command line?
The OpenDesign Alliance has libraries for dgn and dwg with pdf capabilities.
You could could use them to create the command line utility.
Decision Graphics http://www.dgnlink.com/ has a number of products that convert DGN to DWG, all of which can be run from a command line.
Once you have the DWG files, you can use one of the command line DWG to PDF converters (I can't recommend a specific one but a quick Google will find loads), or if you have a copy of AutoCAD or AutoCAD LT, you could write a script for that to convert the DWGs by using the DWG To PDF plotter.
From command line parameters, you can not do it. But you can create a Visual Basic or VB.NET application that will lunch microstation to do it for you.
I have been struggling with this one for a long time. All of the existing tools out there require expensive per-user licenses, which was a no-go for my implementation.
I solved the issue with a combination of three things:
Downloaded Bentley Viewer. This is their 100% free viewing/printing application.
Set up a virtual Windows postscript printer using GhostScript and RedMon. There are various guides online for this, and it can be a bit tricky to track down all of the prerequisites, but it is quite stable once set up correctly. Here is one guide: GhostScript/RedMon Guide
Use a "Key-In" script to pass print commands to Bentley View. This involves simply creating a text file with the required commands (List of Commands) and passing it AND the file you want to convert on the command line as such:
BentleyView.exe -M [Filename.dgn] -S[KeyIn FileName]
Please note that you need a space between the -M and the DGN filename but NOT between the -S and the Key-In script filename.
The script I used to simply print the document and then quit the GUI was:
PRINT PRINTERNAME PDFWriter
PRINT EXECUTE
QUIT
This is not a perfect solution at all, especially since it requires the installation of Bentley View and it also opens a UI when called (although it does close it immediately after printing).

How to use command-line arguments to print ms office files?

We are doing an app to manage and print Word, Excel, PowerPoint, and PDF files...
No application can be shown to the user when printing.
To do that, we find some command-line arguments that work well:
(using openoffice.org)
"C:\Program Files\OpenOffice.org 3\program\soffice.exe" -norestore -nofirsts tartwizard -nologo -headless -pt MicrosoftXPSDocumentWriter doc1.doc
(using ms word)
"C:\Program Files\Microsoft Office\Office\WINWORD.EXE" doc1.doc /q /n /mFilePrintDefault /mFileExit
But we just can't find any option to set the page range to print...
Is this possible? Another option to print those documents without showing anything to the user?
Thanks for reading.
any ideas would be appreciated
I would really rethink doing this app in Java. If the application is to manage word documents, and your interaction with word consists of assumptions that word is installed on the local machine, then java isn't adding anything to the party. .NET is likely the right way to go here (where you could easily interact with the office com objects to get what you need).
That being said, for open office, look at the open office SDK which you would have to make as part of your installer for this app.
For Microsoft Office, I would look at a Java-COM bridge (such as Jacob) to call the COM objects. If that is not an option, you could as part of your install process install a Macro into Word that you could call with the /m parameter and pass in the range values you need - but that would get very ugly very fast.

Categories

Resources