How to get part of a string

HI

df -h
Filesystem Size Used Avail Use% Mounted on

/dev/cciss/c0d1p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-1
/dev/cciss/c0d2p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-2
/dev/cciss/c0d3p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-3
/dev/cciss/c0d4p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-4
/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5

Some how i jus want to get whats the code for the cluster
which is BD55

now /xxx/xxxx/ is same for every line and after US55(this value
different for every server) there would be a - (BD55-)

I would be really help full if any one can help me

Thanks for help

On Sun, Sep 2, 2012 at 7:37 PM, Fosiul A. [email protected]
wrote:

/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5

Some how i jus want to get whats the code for the cluster
which is BD55

now /xxx/xxxx/ is same for every line and after US55(this value
different for every server) there would be a - (BD55-)

I would be really help full if any one can help me

One way would be to read this line by line and use Regexp

e.g.

irb(main):001:0> line = ‘/dev/cciss/c0d5p1 1.8T 88M 1.7T 1%
/xxx/xxxx/BD55-5’
=> “/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5”
irb(main):002:0> line[%r{BD\d+(?=-\d$)}]
=> “BD55”

Kind regards

robert

On Sep 2, 2012, at 14:23 , Fosiul A. [email protected] wrote:

irb(main):001:0> line =‘/dev/cciss/c0d11p1 /xxx/xxxxx/BD55-11
ext3 defaults,noatime,nodiratime 1 0’
=> “/dev/cciss/c0d11p1 /xxx/xxxx/BD55-11 ext3
defaults,noatime,nodiratime 1 0”
irb(main):002:0> line[%r{US\d+(?=-\d$)}]
=> nil

That is working perfectly. There is no “US” anywhere in your string.

On Sun, Sep 2, 2012 at 11:30 PM, Ryan D. [email protected]
wrote:

That is working perfectly. There is no “US” anywhere in your string.
Also the line has a completely different structure from what was
presented in the first posting of this thread.

Cheers

robert

Robert K. wrote in post #1074348:

On Sun, Sep 2, 2012 at 7:37 PM, Fosiul A. [email protected]
wrote:

/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5

Some how i jus want to get whats the code for the cluster
which is BD55

now /xxx/xxxx/ is same for every line and after US55(this value
different for every server) there would be a - (BD55-)

I would be really help full if any one can help me

One way would be to read this line by line and use Regexp

e.g.

irb(main):001:0> line = ‘/dev/cciss/c0d5p1 1.8T 88M 1.7T 1%
/xxx/xxxx/BD55-5’
=> “/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5”
irb(main):002:0> line[%r{BD\d+(?=-\d$)}]
=> “BD55”

Hi
but its not working

irb(main):001:0> line =‘/dev/cciss/c0d11p1 /xxx/xxxxx/BD55-11
ext3 defaults,noatime,nodiratime 1 0’
=> “/dev/cciss/c0d11p1 /xxx/xxxx/BD55-11 ext3
defaults,noatime,nodiratime 1 0”
irb(main):002:0> line[%r{US\d+(?=-\d$)}]
=> nil