Parseing Text file issue it displays correctly in Note Pad

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Parseing Text file issue it displays correctly in Note Pad

Post by kpassaur » Thu May 24, 2007 10:17 pm

This is one of the most unusual things I have come across. I have a text file that displays correclty in notepad and I want to parse it out, but I get strange results. I can open a new copy of notepad, copy and paste the text, save it with a different file name and then it will work.

So, thinking quickly I though I would read each line and rewrite the file – that didn’t work.

When I read the file the first line show it shows “LINEA=ÿþâ€Â

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu May 24, 2007 11:36 pm

If you look at it with a hex editor (hex on the left, ascii on the right) you'll see there are unexpected characters at the start of the file:

Image

So the file content is the problem, as to the solution I need to think on that a bit...

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri May 25, 2007 12:10 am

It's clunky, but I think the quickest way without finding and installing other software would be to open the file in Notepad, and then save it being sure the ANSI option is selected in the Encoding box (tab to that box and send A). I don't have time now to code that but it shouldn't be any problem for someone of your experience :)

There may be some vbscript trick too...

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 25, 2007 4:29 am

Any method I can think of outside of using notepad will require you to evaluate every single character and compare it to a list of acceptable characters. NotePad will do that for you pretty much effortlessly and fast.

I'm sure you want the process to look clean. Try opening the file in notepad using Run Program>notepad filename with RP_WINDOWMODE set to 0. Then use WaitWindowOpen>Notepad* and the next line will be MoveWindow>Notepad*,-10000,-10000. This gets the work off screen and avoids the "clunky" look. Then work with the Notepad window using keystroke inputs. Get the text into the clipboard using Ctrl+A and Ctrl+C the rest should be easy. Close Notepad then use GetClipboard>file to put the file into the script. Then if you use Separate>file,%CRLF%,line you have every line captured as a variable named "line_x" where the "x" is the line number.

If you need more I can put together a sample sometime tomorrow.

Other ideas are welcome.

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Flashing Screen

Post by kpassaur » Fri May 25, 2007 8:14 am

Thank you, I used the following to make it work - I hate it when people don't post what they actually did.

DeleteFile>c:\consolegrab\clean.txt
Let> RP_WINDOWMODE=0
Run Program>notepad c:\consolegrab\output.txt
WaitWindowOpen>Notepad*
MoveWindow>Notepad*,-1000,-1000
SetFocus>Notepad*
Press Ctrl
Send>a
Release Ctrl
Press Ctrl
Send>c
Release Ctrl
GetClipBoard>cleantxt
WriteLn>c:\consolegrab\clean.txt,result,%cleantxt%

I wrote the file to text instead of taking your advice. As what this script is going to do is allow a user to highlight text, find the position, and write the line number, start and end postion to a text file. It will repeat it as many times as the user wants. Once this is done, another script will process the output file from this one allowing a user to parse as much data as they want.

However, when I run the script the screen flashes, very briefly, any ideas on to prevent this?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 25, 2007 3:13 pm

However, when I run the script the screen flashes, very briefly, any ideas on to prevent this?
I don't see a blip on my LCD monitor. Probably slow response time :( One thing you could try is to mask it by popping a message. My favorite is: "Processing please wait..." That one covers a lot of ground.
I wrote the file to text instead of taking your advice.
I was looking at your posted code and assumed you wanted to deal with individual lines.
I hate it when people don't post what they actually did.
Yes, without feedback its hard to feel good about helping. And there's really only two reasons for one forum member to help another forum member. The first is learning and the second is to feel good about helping.

One more thing, you need a line to close notepad otherwise you'll end up with stranded notepad sessions.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri May 25, 2007 3:26 pm

vbscript FileSystemObject has a format argument TristateFalse to open a text file as ASCII, so the vbscript gurus could probably do this directly.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Re: Flashing Screen

Post by Me_again » Fri May 25, 2007 3:27 pm

kpassaur wrote:I hate it when people don't post what they actually did.
Yep, agreed, that's frustrating...

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts