Doubt in grep command
+8
akalya
hansi
Nazneennazim
SakeenaHarris
anand
Christopher
Maithreyi
lalitha
12 posters
Page 1 of 3 • 1, 2, 3
Re: Doubt in grep command
can u tell me an example wher v use * and . in grep
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
ls | grep "ab."
Will print all files starting with ab and having one another character, say
abc
abd
ab0
abf
Will print all files starting with ab and having one another character, say
abc
abd
ab0
abf
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: Doubt in grep command
ls | grep "ab*"
will give files with ab and anynumber of characters
say abcdef, abcd,abc,abd,ab0
will give files with ab and anynumber of characters
say abcdef, abcd,abc,abd,ab0
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: Doubt in grep command
oh okie... thansk maithu
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
[@oracleclient ~]$ cat>ram
ali
amri
ajay
amit
anil
[@oracleclient ~]$ grep "am." ram
amri
amit
[@oracleclient ~]$ grep "aj*" ram
ali
amri
ajay
amit
anil
[@oracleclient ~]$ grep "aj." ram
ajay
wy did this happen
ali
amri
ajay
amit
anil
[@oracleclient ~]$ grep "am." ram
amri
amit
[@oracleclient ~]$ grep "aj*" ram
ali
amri
ajay
amit
anil
[@oracleclient ~]$ grep "aj." ram
ajay
wy did this happen
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
oh sryc hris... i jus had an accompanyin doubt
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
actually the * here means like zero or more occurence of the particular alphabet.....
so in aj* it ll print all the words startin with a or aj or ajj
where j can zero or more occurrences
so in aj* it ll print all the words startin with a or aj or ajj
where j can zero or more occurrences
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: Doubt in grep command
why did "aj." print ajay... dot means any one charac more,doe
sn't it?
sn't it?
SakeenaHarris- Posts : 7
Points : 13
Join date : 2010-03-08
Re: Doubt in grep command
i think aj. will print all entries startin wit aj...
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
when u r using it in grep, it means anyline which contains "ab+any one character". ajay has (ab+a), so obviously it ll display. Suppose if u want to search for a complete word, use
It ll not display 'ajay'
- Code:
grep -w 'aj.' <filename>
It ll not display 'ajay'
Re: Doubt in grep command
[@oracleclient ~]$ grep "j." ram
ajay
[@oracleclient ~]$ grep "n." ram
anil
[@oracleclient ~]$ grep "m." ram
amri
amit
ajay
[@oracleclient ~]$ grep "n." ram
anil
[@oracleclient ~]$ grep "m." ram
amri
amit
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
wat does this dot exactly do??
if my file content is this way
[@oracleclient ~]$ cat ram
ali
amri
ajay
amit
anil
aj
an
still t prints this op
[@oracleclient ~]$ grep "j." ram
ajay
[@oracleclient ~]$ grep "aj." ram
ajay
wats the logic
if my file content is this way
[@oracleclient ~]$ cat ram
ali
amri
ajay
amit
anil
aj
an
still t prints this op
[@oracleclient ~]$ grep "j." ram
ajay
[@oracleclient ~]$ grep "aj." ram
ajay
wats the logic
lalitha- Posts : 14
Points : 16
Join date : 2010-03-08
Re: Doubt in grep command
by default it wont search for complete word. Even if a part of a word matches the search pattern, it ll be displayed.
grep "j." ram -> ajay
grep "aj." ram -> ajay
grep "j." ram -> ajay
grep "aj." ram -> ajay
Re: Doubt in grep command
oracleclient march]$ grep -i -e 'fruit' | -f list1 list2
-bash: -f: command not found
Followed the syntax given, but getting an error
-bash: -f: command not found
Followed the syntax given, but getting an error
Nazneennazim- Posts : 10
Points : 16
Join date : 2010-03-01
Re: Doubt in grep command
-f is used to mention more than one file to search for the pattern from.
Am i right or wrong?
Am i right or wrong?
Nazneennazim- Posts : 10
Points : 16
Join date : 2010-03-01
Re: Doubt in grep command
grep "xy." <filename>,,,,,,,,vl print al d lines starting frm 'xy' containing ny no of char
grep "xy*" <filename>,,,,,,,,vl print al d lines containing 'x' anywhere in d line,,,it has nthng 2 do wid 'y'
$ cat > grepdemo.txt
iftthen
ifelse
found
print
hault
answer
$ grep "if." grepdemo.txt
iftthen
ifelse
$ grep "fi." grepdemo.txt
$ grep "fi*" grepdemo.txt
iftthen
ifelse
found
$ grep "ia*" grepdemo.txt
iftthen
ifelse
print
grep "xy*" <filename>,,,,,,,,vl print al d lines containing 'x' anywhere in d line,,,it has nthng 2 do wid 'y'
$ cat > grepdemo.txt
iftthen
ifelse
found
hault
answer
$ grep "if." grepdemo.txt
iftthen
ifelse
$ grep "fi." grepdemo.txt
$ grep "fi*" grepdemo.txt
iftthen
ifelse
found
$ grep "ia*" grepdemo.txt
iftthen
ifelse
hansi- Posts : 6
Points : 8
Join date : 2010-03-03
Age : 37
Location : u.p.
Re: Doubt in grep command
-f is used to search for multiple patterns. Also search patterns are stored in separate file.
Example
Instead of giving multiple patterns as arguments using -e switch, u can save it in a separate file and pass tat file as an argument to grep command using -f switch.
Example
- Code:
$ cat 1.txt
orange yellow red
red green black
black white yellow
blue pink cyan
red green blue
white black cyan
$ cat search.txt
black
cyan
$ grep -f search.txt 1.txt
red green black
black white yellow
blue pink cyan
white black cyan
Instead of giving multiple patterns as arguments using -e switch, u can save it in a separate file and pass tat file as an argument to grep command using -f switch.
Re: Doubt in grep command
wat is the difference between ...
grep [a-z] filename and grep [!a-z] filename ???
[335802@oracleclient ~]$ cat list1
mango
orange
pineapple
lemons
[335802@oracleclient ~]$ grep [a-z] list1
mango
orange
pineapple
lemons
[335802@oracleclient ~]$ grep [!a-z] list1
mango
orange
pineapple
lemons
grep [a-z] filename and grep [!a-z] filename ???
[335802@oracleclient ~]$ cat list1
mango
orange
pineapple
lemons
[335802@oracleclient ~]$ grep [a-z] list1
mango
orange
pineapple
lemons
[335802@oracleclient ~]$ grep [!a-z] list1
mango
orange
pineapple
lemons
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: Doubt in grep command
'!' doesn't have any significance. it ll be considered jus like a character.
- Code:
$ cat 1.txt
orange yellow red
red blue green
white black cyan
cyan pink orange
red! blue! green!
BLUE! WHITE! BLACK!
$ grep '[a-z]' 1.txt
orange yellow red
red blue green
white black cyan
cyan pink orange
red! blue! green!
$ grep '[!a-z]' 1.txt
orange yellow red
red blue green
white black cyan
cyan pink orange
red! blue! green!
BLUE! WHITE! BLACK!
$ grep '[!]' 1.txt
red! blue! green!
BLUE! WHITE! BLACK!
Re: Doubt in grep command
! doesn't seem to have a significance in grep.However, ^ means negation.
Suppose cat >> list1
1234
now grep [a-z] list1
mango
orange
pineapple
lemons
grep [!a-z] list1
mango
orange
pineapple
lemons
but,
grep [^a-z] list1
1234
Suppose cat >> list1
1234
now grep [a-z] list1
mango
orange
pineapple
lemons
grep [!a-z] list1
mango
orange
pineapple
lemons
but,
grep [^a-z] list1
1234
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: Doubt in grep command
Yes. ^ inside square bracket means 'negation' and ^ outside square bracket means 'starts with'.
Re: Doubt in grep command
jus like j* denotes 0 or more occurence...how do i specify 1 or more occurence in a grep command???
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Page 1 of 3 • 1, 2, 3
Similar topics
» GREP TO EXTRACT NON DIGIT FROM EXPRESSION
» awk command doubt
» tee command doubt
» doubt in sort command!!!
» doubt in sort command
» awk command doubt
» tee command doubt
» doubt in sort command!!!
» doubt in sort command
Permissions in this forum:
You cannot reply to topics in this forum
|
|