Deleting Lines Over Multiple Files...
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Deleting Lines Over Multiple Files...
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!
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
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.
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]
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]
I choose to fight with a sack of angry cats.
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
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
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
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
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.
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.
I choose to fight with a sack of angry cats.