Page 1 of 1

Deleting Lines Over Multiple Files...

Posted: Thu Jul 07, 2005 3:16 pm
by jpe110
I have an analytical instrument that outputs data in .txt files, 96 of them at a time. These text files have lines of information that need to be deleted. The line numbers do not necessarily have the same information on each line, but the lines that need to be deleted are congruent throughout each set of 96. I've been refered to the Wildedit forum because Textpad doesn't seem to have this capability. If anyone needs a sample of the files, I'll be glad to send you what you need. Does anyone know how to do this? Thanks!

Posted: Thu Jul 07, 2005 5:25 pm
by talleyrand
I had told jpe to give WildEdit a whirl based on the one file I had seen. To me it looked like remove everything to the first # from there, the data he'd like to preserve is contained between the # and the *. The number of sets of data in a file may change from run to run is the kicker I think. I thought a suped up regular expression could handle it and then let WE just run on all the files in the directory.

Thoughts? Snippet of the file follows.

Code: Select all

Date: 29-Jun-05
Time: 12:20:00
Label: 2AP Time
O Square Wave Voltammetry

Exp. Conditions:
Init E (mV) = 800
Final E (mV) = -1200
Step E (mV) = 4
S.W. Amplitude (mV) = 25
Frequency (Hz) = 15
Samples per Point = 256
Quiet Time (sec) = 2
Sensitivity (A/V) = 1E-5

3 Sets of Data
Number of Data Points for Each Set = 500
##
Potential (mV), Current (A)

Difference Data
#
796.0, +6.533e-005
...{snip}
*
Forward Data
#
796.0, -8.457e-006
...{snip}
*
Reverse Data
#
-1200.0, +3.136e-005
...{snip}
*
**

After thinking about it some more, maybe it'd be even easier to extract any line that starts with a potentially signed number. Macro it so it bookmarks those lines, inverts selection, cuts bookmarked lines and then removes the first line since it'd be the one indicating how many data sets the file contained.


[edit]
Using POSIX regular expressions,
^-[0-9]+|^[0-9]+
should extract all lines starting with numbers. I suspect someone will ammend this to remove the cheesey remove first line step
[/edit]

Posted: Thu Jul 07, 2005 9:28 pm
by s_reynisson
Must be getting rusty, had to hack back and forth to get it right ;)

The decheesed version using TP with a POSIX RegEx:
^-?[0-9]+\.
gives me
796.0, +6.533e-005
796.0, -8.457e-006
-1200.0, +3.136e-005
using the mark-all-invert-delete bookmarked lines ploy.

Using WE:
(Date.+?\r\n#\r\n)|(\r\n\*[^#]+#)|(\r\n\*\r\n\*+)
gives me
796.0, +6.533e-005
...{snip}
796.0, -8.457e-006
...{snip}
-1200.0, +3.136e-005
...{snip}

HTH

Posted: Fri Jul 08, 2005 2:25 pm
by jpe110
I gathered that you guys have come up with a solution....How do I implement it?

Posted: Fri Jul 08, 2005 3:44 pm
by talleyrand
If you buy WildEdit, pasting the (Date.+?\r\n#\r\n)|(\r\n\*[^#]+#)|(\r\n\*\r\n\*+) into the Find What, check the Regular Expression and point it to the appropriate directory. That regular expression will replace the gunk with nothing.

If you want to stick with TextPad, create a macro that does a Find using ^-?[0-9]+\. as your regular expression {POSIX syntax}, Mark All, Invert All Bookmarks, Cut Other Bookmarked lines. Save that and apply to any file you want cleaned.

And as always, thanks to s_reynisson for helping with those pesky regexps.

Thanks!

Posted: Wed Jul 13, 2005 9:15 pm
by jpe110
Thanks for the help, you guys are awesome!