From: Josh Cheek Date: 2011-07-27T22:48:05+09:00 Subject: Re: String manuplation example --90e6ba48856d1729c104a90d4c0c Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 27, 2011 at 8:26 AM, kotin 76 wrote: > Hi All, > > Thanks for your quick reply's. > > I executed the program from wt hans suggestd. it works fine. > > some times i am going to extract at other location like below > > string = "45225016 3702464 39225208 9% /dev/sda4 " > string = "45225016 3702464 39225208 9% /dev/sda1256 " > string = "45225016 3702464 39225208 9% /dev/sdaERT7890 " > string = "45225016 3702464 39225208 9 /dev/sda4sdfsd " > string = "45225016 3702464 39225208 9% /dev/sda4fsdfs " > > i understand one thing, > > we can success if we create the logic to extract string starting with > /dev and to up to the first non alpha numeric. > > have you suggest any idea for this? > > Regards > kotin > > > > > > > Josh Cheek wrote in post #1013337: > > On Wed, Jul 27, 2011 at 7:54 AM, kotin 76 wrote: > > > >> 1. i dont know how many character will come after /dev like it may come > >> Random string like > >> > >> > > 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 = line.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%/" > > # >> > > -- > Posted via http://www.ruby-forum.com/. > > Here, I put your strings into rubular http://rubular.com/r/dbuEen46gb How about trying to create a regex that matches your data and then posting it here for feedback. --90e6ba48856d1729c104a90d4c0c--