Hi,
I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out?
[root work/tmp]$ cat b.ksh
AasdjfhB
57834B
86234B
472346B
I want to print the line which is starting with either A or 8 and ending with B. My expected result should be
AasdjfhB
86234B
I have tried with grep command but getting unexpected result,
[root work/tmp]$ grep '[^A8]B' b.ksh
AasdjfhB
57834B
86234B
472346B
anbu23
March 8, 2013, 12:24am
2
$ grep '^[A8].*B$' file
AasdjfhB
86234B
Hi,
I have tried this. But it is not working. I am not getting any result.
[root work/tmp]$ grep '[^A8].*B$' k.ksh
[root work/tmp]$
anbu23
March 8, 2013, 12:37am
4
Note position of Circumflex(^) in my code which matches regular expression at the beginning of the line
Circumflex (^) as the first character in the brackets reverses the sense: it matches any one character not in the list
$ grep '^[A8].*B$' file
AasdjfhB
86234B
[^a-c]
-- A
^
inside
[ ]
negates the pattern like
[^a-c]
which means anything other than a till c
^[a-c]
means any pattern starting either with
a,b or c
Hi all,
Thank you . It is working fine now.
could you please tell me what is the meaning of the symbol "." in
grep '^[A8].*B$' b.ksh
Jotne
March 8, 2013, 2:57am
8
.
represent any character
The *
behind makes it repeat.
Whit awk
awk '/^[A8].*B$/' infile
anbu23
March 8, 2013, 2:57am
9
. Match any single character
"." matches a single character and when combined with "*" mean any number of character