--90e6ba48856d4da5f804a90cd6a9 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 27, 2011 at 7:54 AM, kotin 76 <kotin76 / yahoo.com> wrote: > Hi Hans Mackowiak and Shah, > > Thanks for your quick reply. > > I am executed your code. its giving string /dev/sda4. > > its really use full for me. > > just i want to know onemore logic for > > 1. i dont know how many character will come after /dev like it may come > /dev/sda4 , /dev/sda1256 or /dev/sdaERT7890. But my aim is to extract > the that word from /dev to end of that word like "/dev/sda4" , > "/dev/sda1256" , "/dev/sdaERT7890". for this what logic i need to add > after /dev in below of your logics > > > stv t.gsub("/dev/?") > string.match(/[\/\w]+/)[0]# "/dev/?" > > > Random string like > > string /dev/sda4 45225016 3702464 39225208 9% /" > string /dev/sda1256 45225016 3702464 39225208 9% /" > string /dev/sdaERT7890 45225016 3702464 39225208 9% > /" > string /dev/sda4sdfsd 45225016 3702464 39225208 9% > /" > string /dev/sda4fsdfs 45225016 3702464 39225208 9% > /" > > > form above string i need to extract /dev/sda4 , /dev/sda1256, > /dev/sdaERT7890 , /dev/sda4sdfsd and /dev/sda4fsdfs > > > please suggest your logic > > > Regards > Kotin > > It's not really clear to me what "extract" means. Are you interested in knowing what it begins with, or are you interested in removing it from the string, or both? Anyway, looking at your examples, this works. But if you end up with spaces in the filenames, it won't work (hence the reason I think it's stupid how Unix loves turning everything into whitespace separated values). string /dev/sda4 45225016 3702464 39225208 9% / /dev/sda1256 45225016 3702464 39225208 9% / /dev/sdaERT7890 45225016 3702464 39225208 9%/ /dev/sda4sdfsd 45225016 3702464 39225208 9%/ /dev/sda4fsdfs 45225016 3702464 39225208 9%/" string.each_line do |line| first, rest ine.split(/\s+/, 2) p first p rest puts end # >> "/dev/sda4" # >> "45225016 3702464 39225208 9% /\n" # >> # >> "/dev/sda1256" # >> "45225016 3702464 39225208 9% /\n" # >> # >> "/dev/sdaERT7890" # >> "45225016 3702464 39225208 9%/\n" # >> # >> "/dev/sda4sdfsd" # >> "45225016 3702464 39225208 9%/\n" # >> # >> "/dev/sda4fsdfs" # >> "45225016 3702464 39225208 9%/" # >> --90e6ba48856d4da5f804a90cd6a9--