GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Go down

GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by itssrinath on Fri Mar 12, 2010 2:05 pm

The file grep.txt contains:
hi
hello
everybody
1987
15
5^
xx.y
HELLO
HI
hi

[335931@oracleclient ~]$ grep [0-9] grep.txt
1987
15
5^

[335931@oracleclient ~]$ grep [^0-9] grep.txt
[335931@oracleclient ~]$
(the second command to extract non digits does nt print anything to the output terminal).Pls help me resolve this.

itssrinath

Posts : 4
Points : 5
Join date : 2010-02-26

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by mightyganesh on Fri Mar 12, 2010 2:12 pm

hey i am getting output for that ! i dont know how u could not

i got
Code:

[336474@oracleclient ~]$ cat > grep.txt
hi
hello
everybody
1987
15
5^
xx.y
HELLO
HI
hi
[336474@oracleclient ~]$ cat grep.txt
hi
hello
everybody
1987
15
5^
xx.y
HELLO
HI
hi
[336474@oracleclient ~]$ grep [0-9] grep.txt
1987
15
5^
[336474@oracleclient ~]$ grep [!0-9] grep.txt
1987
15
5^
[336474@oracleclient ~]$ grep [^0-9] grep.txt
hi
hello
everybody
5^
xx.y
HELLO
HI
hi
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by akalya on Fri Mar 12, 2010 2:12 pm

its working here....
[335802@oracleclient ~]$ cat>hi
123
hello
hi
5678

[9]+ Stopped cat > hi
[335802@oracleclient ~]$ grep [0-9] hi
123
5678
[335802@oracleclient ~]$ grep [^0-9] hi
hello
hi
[335802@oracleclient ~]$ grep -v [0-9] hi
hello
hi
[335802@oracleclient ~]$ grep -v [a-z] hi
123
5678
[335802@oracleclient ~]$ grep [^a-z] hi
123
5678

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Maithreyi on Fri Mar 12, 2010 2:13 pm

grep [0-9] grep.txt
1987
15
5^
[335818@oracleclient ~]$ grep [!0-9] grep.txt
1987
15
5^
[335818@oracleclient ~]$ grep [^0-9] grep.txt
hi
hello
everybody
5^

Its printing!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 30
Location : Haldia

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Janani on Fri Mar 12, 2010 2:13 pm

i got this ...........

[335765@oracleclient ~]$ grep '[^0-9]' grep.txt
hi
hello
everybody
5^
xx.y
HELLO
HI
hi

Janani

Posts : 1
Points : -1
Join date : 2010-02-26

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by urvershi on Fri Mar 12, 2010 2:15 pm

use dis it ll work.
grep -v [0-9] grep.txt

urvershi

Posts : 21
Points : 70
Join date : 2010-02-26

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by mightyganesh on Fri Mar 12, 2010 2:18 pm

but i got a doubt now!

in the
Code:
[336474@oracleclient ~]$ grep [^0-9] grep.txt
hi
hello
everybody
5^
xx.y
HELLO
HI
hi

in this y am i getting 5^ in the output list???

if it accepts all the words which contain other than [0-9]
(5^ contains ^ which does not fall in [0-9])
what should be my command so as to accept the words which does not have any numbers in them????
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by akalya on Fri Mar 12, 2010 2:18 pm

@maithreyi and @ganesh
wat is use of ! in [!a-z] and ^ in [^a-z]??

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by mightyganesh on Fri Mar 12, 2010 2:19 pm

thanks
grep -v [0-9] grep.txt
works
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by akalya on Fri Mar 12, 2010 2:20 pm

@ganesh

try using grep -v [0-9] filename

it'll print only the words

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by jeeva on Fri Mar 12, 2010 2:23 pm

cat greptest

hi
hello
everybody
1987
15
5^
xx.y
HELLO
HI
hi


[335814@oracleclient ~]$ grep -v [0-9] greptest.txt
hi
hello
everybody
xx.y
HELLO
HI
hi
[335814@oracleclient ~]$ grep -v [^0-9] greptest.txt
1987
15


in both above cases ^5 is missing....
same way when -v is not used ^5 is present in both

why!!!


Last edited by jeeva on Fri Mar 12, 2010 2:30 pm; edited 3 times in total

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by mightyganesh on Fri Mar 12, 2010 2:24 pm

[^a-z] is negation of[a-z]

[a-z] says accept if it contains any character from a to z

[^a-z] says accept if it contains any other character other than a to z
(it will accept abc123 because it contains 123 which are character other than a to z)

but -v [a-z] says dont accept if it contains any character from a to z
(it will not accept abc123 because it contains abc which are character from a to z ) (i.e. even though it contains 123 it is rejected because it contains abc)
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Maithreyi on Fri Mar 12, 2010 2:30 pm

[^a-z] says accept if it contains any other character other than a to z
(it will accept abc123 because it contains 123 which are character other than a to z)

Therefore [^0-9] gives ^5 because it contains character '^' (other than 0-9)

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 30
Location : Haldia

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Sowmini on Fri Mar 12, 2010 5:54 pm

Am not able to get output for
grep [^0-9] grep.txt
grep [!0-9] grep.txt

Sowmini

Posts : 2
Points : 2
Join date : 2010-03-03

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by sanjidhkaran on Mon Mar 15, 2010 2:17 pm

hey buddy try this...
code:
#$^@#$%^&^@#$!@$%^&*(@#@$@%$&*(&#%$&#&(#%@!!%():-(:-( albino study

sanjidhkaran

Posts : 1
Points : 1
Join date : 2010-03-08

View user profile

Back to top Go down

dats creepy sanjidh..:P

Post by Jay Dave on Mon Mar 15, 2010 2:22 pm

sanjidhkaran wrote:hey buddy try this...
code:
#$^@#$%^&^@#$!@$%^&*(@#@$@%$&*(&#%$&#&(#%@!!%():-(:-( albino study

Jay Dave

Posts : 4
Points : 4
Join date : 2010-03-03

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by jeeva on Mon Mar 15, 2010 3:59 pm

how to try that code... from where till where exactly!!! wat happens!!

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by jeeva on Mon Mar 15, 2010 4:00 pm

this code is being accepted... is that the thing!!!

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

View user profile

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Christopher on Mon Mar 15, 2010 4:07 pm

sanjidhkaran wrote:hey buddy try this...
code:
#$^@#$%^&^@#$!@$%^&*(@#@$@%$&*(&#%$&#&(#%@!!%():-(:-( albino study

wat r u trying to say???
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: GREP TO EXTRACT NON DIGIT FROM EXPRESSION

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum