From: kotin 76 Date: 2011-07-27T22:26:02+09:00 Subject: Re: String manuplation example 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/.