Re: autodetecting MBR location
Stephen says: > "Russell" == Russell Coker <[EMAIL PROTECTED]> writes: >Russell> Right. The s/[0-9]+$// should do it. > > > > s/\d+$// not s/[0-9]+$//. The former will continue to work in Unicode > capable file-systems (assuming Linux ever supports such). > > It supports them right now - try setting the locale to a UTF-8 locale and "cat > À". You now have a file with a name in Unicode. As for the job being done, [0-9] sounds better. Even if the device names stop being in Unicode, they won't go to non-Arabic numerals, and it's questionable whether we would want to strip those numbers out if they are there. -- David Starner - [EMAIL PROTECTED]
Re: autodetecting MBR location
> "Russell" == Russell Coker <[EMAIL PROTECTED]> writes: Russell> Right. The s/[0-9]+$// should do it. s/\d+$// not s/[0-9]+$//. The former will continue to work in Unicode capable file-systems (assuming Linux ever supports such). Nothing to see here, move along... -- Stephen "And what do we burn apart from witches?"... "More witches!"
Re: autodetecting MBR location
On Wednesday 03 January 2001 00:24, Tollef Fog Heen wrote: > | My lilo configuration scripts need to be able to infer the correct > | location for the MBR. I am currently using the following algorithm: > | take root fs device from /etc/fstab and do the following: > | s/[0-9]*// > | s/part$/disc/ > > What is the use of the first s/? Unless your first letter is a digit, > it will just remove the zero-width string '' between the first / and > the beginning of the string. > > A better solution will probably be to > > s/[0-9]$// > > which will remove 5 from /dev/hda5. Correct. In my code I have s/[0-9]*$//. That part of my email was re-typed from memory and I missed a character. The discussion this generated was enlightening though. On Wednesday 03 January 2001 01:00, Bart Schuller wrote: > However, stylistically s/[0-9]*// is better written as s/[0-9]+// > because the case where no digits match is better classified as > "not a match". Good point! I have changed my code accordingly. On Wednesday 03 January 2001 02:33, Tollef Fog Heen wrote: > s/\d+// on devfs devices is dangerous, you'll get rid of the host > number: > > perl -e '$_ = "/dev/ide/host0/bus0/target0/lun0/part1"; s/[0-9]+//; print > $_,"\n"' /dev/ide/host/bus0/target0/lun0/part1 Right. The s/[0-9]+$// should do it. Now does anyone have suggestions about what file name I should give to my mini-perl program or what else I should do to make it generally usable? -- http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/projects.html Projects I am working on http://www.coker.com.au/~russell/ My home page
Re: autodetecting MBR location
* (Colin Watson) | Contrary to the subconscious assumption many people make, the first | priority for a regex is to match earliest, not to match longest. | regex(7) specifically mentions this: For a non-POSIX regex, that is. | >However, stylistically s/[0-9]*// is better written as s/[0-9]+// | >because the case where no digits match is better classified as | >"not a match". | | True; even s/\d+// or s/\d+$// (assuming that the partition numbers are | always at the end, even in devfs - I'm not familiar with that). s/\d+// on devfs devices is dangerous, you'll get rid of the host number: perl -e '$_ = "/dev/ide/host0/bus0/target0/lun0/part1"; s/[0-9]+//; print $_,"\n"' /dev/ide/host/bus0/target0/lun0/part1 -- Tollef Fog Heen Unix _IS_ user friendly... It's just selective about who its friends are.
Re: autodetecting MBR location
Bart Schuller <[EMAIL PROTECTED]> wrote: >On Tue, Jan 02, 2001 at 02:24:22PM +0100, Tollef Fog Heen wrote: >> | s/[0-9]*// >> | s/part$/disc/ >> >> What is the use of the first s/? Unless your first letter is a digit, >> it will just remove the zero-width string '' between the first / and >> the beginning of the string. >> >> A better solution will probably be to >> >> s/[0-9]$// >> >> which will remove 5 from /dev/hda5. > >You seem to know that $ and ^ anchor a match to the end or the beginning >of a string. So you should also know that in the absence of one of >these characters, the match may start anywhere in the string. So the >statement works fine as it is. That's not true; try it. [EMAIL PROTECTED] ~]$ echo /dev/hda1 | perl -pe 's/[0-9]*//' /dev/hda1 [EMAIL PROTECTED] ~]$ echo /dev/hda1 | perl -pe 's/[0-9]+//' /dev/hda Contrary to the subconscious assumption many people make, the first priority for a regex is to match earliest, not to match longest. regex(7) specifically mentions this: In the event that an RE could match more than one sub- string of a given string, the RE matches the one starting earliest in the string. If the RE could match more than one substring starting at that point, it matches the longest. >However, stylistically s/[0-9]*// is better written as s/[0-9]+// >because the case where no digits match is better classified as >"not a match". True; even s/\d+// or s/\d+$// (assuming that the partition numbers are always at the end, even in devfs - I'm not familiar with that). -- Colin Watson [EMAIL PROTECTED]
Re: autodetecting MBR location
* Goswin Brederlow | > s/[0-9]$// | | > which will remove 5 from /dev/hda5. | | You forgot /dev/hda17, which would become /dev/hda1 with your syntax. you are right. make that regexp a s/[0-9]+$// instead. -- Tollef Fog Heen Unix _IS_ user friendly... It's just selective about who its friends are.
Re: autodetecting MBR location
* Bart Schuller | On Tue, Jan 02, 2001 at 02:24:22PM +0100, Tollef Fog Heen wrote: | > | s/[0-9]*// | > | s/part$/disc/ | > | > What is the use of the first s/? Unless your first letter is a digit, | > it will just remove the zero-width string '' between the first / and | > the beginning of the string. | > | > A better solution will probably be to | > | > s/[0-9]$// | > | > which will remove 5 from /dev/hda5. | | You seem to know that $ and ^ anchor a match to the end or the beginning | of a string. So you should also know that in the absence of one of | these characters, the match may start anywhere in the string. So the | statement works fine as it is. Not on my box: $perl -e '$_ = "/dev/hda5" ; s/[0-9]*//; print '; echo /dev/hda5 $perl -V Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: [snip] It will match the zero-width string between ^ and the first slash. Leftmost is preferred over longer strings, unless you are using a POSIX regex engine, where you are required to match the longest overall. | However, stylistically s/[0-9]*// is better written as s/[0-9]+// | because the case where no digits match is better classified as | "not a match". No, it is classified as 'match a zero width string' which is a perfectly acceptable match and a very much different thing than a non-match. -- Tollef Fog Heen Unix _IS_ user friendly... It's just selective about who its friends are.
Re: autodetecting MBR location
> " " == Tollef Fog Heen <[EMAIL PROTECTED]> writes: > * Russell Coker | My lilo configuration scripts need to be able > to infer the correct location | for the MBR. I am currently > using the following algorithm: | take root fs device from > /etc/fstab and do the following: | s/[0-9]*// | s/part$/disc/ > What is the use of the first s/? Unless your first letter is a > digit, it will just remove the zero-width string '' between the > first / and the beginning of the string. > A better solution will probably be to > s/[0-9]$// > which will remove 5 from /dev/hda5. You forgot /dev/hda17, which would become /dev/hda1 with your syntax. MfG Goswin
Re: autodetecting MBR location
On Tue, Jan 02, 2001 at 02:24:22PM +0100, Tollef Fog Heen wrote: > | s/[0-9]*// > | s/part$/disc/ > > What is the use of the first s/? Unless your first letter is a digit, > it will just remove the zero-width string '' between the first / and > the beginning of the string. > > A better solution will probably be to > > s/[0-9]$// > > which will remove 5 from /dev/hda5. You seem to know that $ and ^ anchor a match to the end or the beginning of a string. So you should also know that in the absence of one of these characters, the match may start anywhere in the string. So the statement works fine as it is. However, stylistically s/[0-9]*// is better written as s/[0-9]+// because the case where no digits match is better classified as "not a match". -- The idea is that the first face shown to people is one they can readily accept - a more traditional logo. The lunacy element is only revealed subsequently, via the LunaDude. [excerpted from the Lunatech Identity Manual]
Re: autodetecting MBR location
* Russell Coker | My lilo configuration scripts need to be able to infer the correct location | for the MBR. I am currently using the following algorithm: | take root fs device from /etc/fstab and do the following: | s/[0-9]*// | s/part$/disc/ What is the use of the first s/? Unless your first letter is a digit, it will just remove the zero-width string '' between the first / and the beginning of the string. A better solution will probably be to s/[0-9]$// which will remove 5 from /dev/hda5. -- Tollef Fog Heen Unix _IS_ user friendly... It's just selective about who its friends are.