Page 1 of 1
Find right-most byte
Posted: Tue Sep 27, 2011 1:04 am
by gcotterl
My text file has 1 million lines each 1,274 characters long.
How can I find the line having the number 9 in the rightmost byte?
For example, how do I find the line in red?
0000000000000000000009999900000
0000000099999000000000000000000
9999000000000000000000000000000
0000000000000000000000000999900
0000000000000099999990000000000
0000000000000000000000000000000
0000000000000000099999900000000
Re: Find right-most byte
Posted: Tue Sep 27, 2011 2:37 am
by ak47wong
Isn't the rightmost byte of the red line in your example "0"? Are you asking how to find a line where their last character is "9"? If so:
Find what: 9$
[x] Regular expression
Posted: Tue Sep 27, 2011 2:58 am
by gcotterl
You are correct.
Ignoring the right-most zeroes, I''m looking for the lines whose last rightmost character is a 9.
Posted: Tue Sep 27, 2011 8:18 am
by ben_josephs
Do you mean that you want to find the line whose rightmost 9 is further to the right than it is on any other line (in which case the trailing zeroes are, by implication, ignored)?
I can't see a way to do this in TextPad.
Posted: Tue Sep 27, 2011 9:00 am
by ak47wong
The only way I can think of, which is entirely kludgy, is first to search for 9$, and if that doesn't find a match, search for 90$, then 900$, and increase the number of zeros until a match is found.
Posted: Tue Sep 27, 2011 9:31 am
by gcotterl
I will make my question clearer:
How can I delete all of the zeroes to the right of the last 9 in each
line?
For example, here are some rows:
0000000000000000000009990000000
0000000099099000000000000000000
9999000000000000000000000000000
0000000000000000000000000099900
0000000000000099999990000000000
0900000000000000000000000000000
0000000000000000099999000000000
This is result I'm looking for:
000000000000000000000999
0000000099099
9999
00000000000000000000000000999
000000000000009999999
09
0000000000000000099999
Then, how do I find the longest line?
Posted: Tue Sep 27, 2011 10:28 am
by ben_josephs
To remove trailing zeroes:
Find what: 0+$
Replace with: [nothing]
[X] Regular expression
Replace All
To remove trailing zeroes only if they follow a
9:
Find what: 90+$
Replace with: 9
[X] Regular expression
Replace All
As already said, you'll have a job getting TextPad to find the longest line.
Posted: Tue Sep 27, 2011 1:10 pm
by gcotterl
Thanks Ben,
Your "To remove trailing zeroes only if they follow a 9:" suggestion did the trick.
Then, to find the longest line, I did several sorts earfch with larger values in the "First Key" box until the longest line was at the bottom.
Gary