Regix in grep or something like this

Hi

/dev/cciss/c0d11p1
/dev/cciss/c0d1p1
/dev/cciss/c0d2p1

#Function to check if the Hardrive is mounted or not
def mount_check(drive_path)
chk_mount=df -h | grep '#{drive_path}' | wc -l
return chk_mount
end

problem is :
its taking
c0d1 also c0d11

but if pass variable c0d1
i just want to get line with has c0d1 , not c0d11

but confused how to do

Can any one please help me

On Fri, Sep 7, 2012 at 1:41 PM, Ferdous ara [email protected]
wrote:

Can any one please help me

man grep

hi
thanks
but i think i know about grep…
but dont know what regix to use …

HI
thanks for the solution
problem is i am not that good in Regix… and Currently I have very less
time to learn …
as I am doing some project and trying to finish this quicly so i am
just asking those small bit when i dont know…
may be after i finish the projet… i will give more time to lear n

the regix i am affer is

/dev/cciss/c0d11p1
/dev/cciss/c0d1p1

c0d1
its end with number
then Charater

p1

also problem is :
i need to provide only c0d1
i cant provide full path

Uh, here we go again. What did you try after your last post. You
should be able to do this with only the most basic of Ruby knowledge.
This is what “df -h” gives me…

Filesystem Size Used Avail Capacity Mounted on

/dev/disk0s2 465Gi 389Gi 75Gi 84% /

devfs 191Ki 191Ki 0Bi 100% /dev

map -hosts 0Bi 0Bi 0Bi 100% /net

map auto_home 0Bi 0Bi 0Bi 100% /home

/dev/disk2s2 1.4Ti 504Gi 893Gi 37% /Volumes/Backup

/dev/disk1s6 466Gi 305Gi 161Gi 66% /Volumes/Spare

def mount_check(drive_path)
%x{df -h}.split(/\n/).each do |line|
if line.split(/\s+/).first == drive_path
return true
end
end

return false
end

mount_check("/dev/disk0s2") => true

The only point to note is you must give the full drive path,
/dev/disk0s2, rather than just part of it, such as disk0s2.

Also this solution and your solution has absolutely nothing to do with
regexs at all.

Please at least attempt to learn how to program before posting another
question.

On Fri, Sep 7, 2012 at 1:57 PM, Ferdous ara [email protected]
wrote:

but i think i know about grep…
but dont know what regix to use …

Sorry, if you asked that question, it’s obvious you don’t know grep.

Sorry… is not it better to give the solution rather then pulling some
else’s Leg ???

ok (I dont know grep,Surrender)
would be able to tell me
which Grep parameter will give me output :

only /dev/cciss/c0d1p1 line by providing c0d1 ,(not cod1p1)

From here :
/dev/cciss/c0d1p1
/dev/cciss/c0d10p1
/dev/cciss/c0d11p1
/dev/cciss/c0d12p1

Thanks

On Sep 7, 2012, at 14:34 , Ferdous ara [email protected] wrote:

From here :
/dev/cciss/c0d1p1
/dev/cciss/c0d10p1
/dev/cciss/c0d11p1
/dev/cciss/c0d12p1

here’s how you can practice it: http://rubular.com

Paste the data above into the “text string” box, then try your regexp in
the regexp box. It’ll show what it matches live. You can then tweak the
regexp until it matches everything you want.

Paste the data above into the “text string” box, then try your regexp in
the regexp box. It’ll show what it matches live. You can then tweak the
regexp until it matches everything you want.

I been to these site before but bit confused about how it works

Under Regular expresson ,i type

c0d1
its give me 3 match …

but i want only 1 math… so how that site helping to build regular
expression ??
Thanks for advise.

From: Ferdous ara [email protected]

I been to these site before but bit confused about how it works

http://www.regular-expressions.info/tutorial.html

It’s your friend.

never mind , its got solution

On Sep 7, 2012, at 15:05 , Ferdous ara [email protected] wrote:

its give me 3 match …

but i want only 1 math… so how that site helping to build regular
expression ??

Writing the regexp is up to you. I’m providing you tools to get faster
feedback so you can learn regexps. Also check out my quickref, it has a
whole section an what can go into a regexp:

http://www.zenspider.com/Languages/Ruby/QuickRef.html#regexen

Am 07.09.2012 23:18, schrieb Ferdous ara:

HI
thanks for the solution
problem is i am not that good in Regix… and Currently I have very less
time to learn …
as I am doing some project and trying to finish this quicly so i am
just asking those small bit when i dont know…
may be after i finish the projet… i will give more time to lear n

A friendly suggestion: please learn now! That will save you
(and us) a lot of time. This really is most basic stuff, and
if you keep asking these kind of questions you risk that people
eventually won’t help you anymore when you are in real trouble.

a simplistic solution:

1.9.3-p194 :001 > drive = ‘c0d1’
=> “c0d1”
1.9.3-p194 :002 > /#{drive}p/ === ‘/dev/cciss/c0d1p1’
=> true
1.9.3-p194 :003 > /#{drive}p/ === ‘/dev/cciss/c0d11p1’
=> false

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs