grep and regular expression

Hi,

I am executing a svnlook command to check to see if the following line exists. I need a regular expression to represent the line.

A /test/test1/qa/test2/index.html
A /test/test1/qa/test3/test.jpg
A /test/test1/qa/test3/test1.jpg
A /test/test1/qa/test4/test.swf

I just need to extract the first line with index.html.

this is what i cud get so far but does not filter out the lne only with index.html

echo "A /content/qa/test/index.html" | grep "^A [A-Za-z0-9/_]"

thanks in advance.

KM

Hi, I don't understand if you need only the line ending with "index.html" or even the full path, so I wrote this tu regexp

 grep "\/test\/test1\/qa\/test2\/index\.html"
 grep "index\.html$"

---------- Post updated at 05:58 PM ---------- Previous update was at 05:57 PM ----------

Sorry, in first regexp you can delete the escape char \

[CODE]
grep "/test/test1/qa/test2/index\.html"
[\CODE]

Thanks kcoder24 for your quick response.

yes i need to check the first letter to be "A" and the last word to be index.html.

Thanks.

I'm not familiar with svnlook, will this work?

grep ^A.*html$
^ - beginning of line
.* - acts as wildcard
$ - end of line 

test..

# echo "A /test/test1/qa/test2/index.html
> A /test/test1/qa/test3/test.jpg
> A /test/test1/qa/test3/test1.jpg
> A /test/test1/qa/test4/test.swf
> html
> A
> html A
> A blah blah html" | grep ^A.*html$
A /test/test1/qa/test2/index.html
A blah blah html
# 


Or

sed -n '/^A.*index\.html/p' file

cheers,
Devaraj Takhellambam

$ 
$ cat f9
A /test/test1/qa/test2/index.html
A /test/test1/qa/test3/test.jpg
A /test/test1/qa/test3/test1.jpg
A /test/test1/qa/test4/test.swf
$ 
$ # awk
$ awk '/^A .*index.html/' f9
A /test/test1/qa/test2/index.html
$ 
$ # perl
$ perl -lne '/^A .*index.html/ && print' f9
A /test/test1/qa/test2/index.html
$ 
$ # grep
$ grep "^A .*index.html" f9
A /test/test1/qa/test2/index.html
$ 
$

tyler_durden

Thanks all the guys and thanks to Fubaya. That worked for me. simple and short. i will try others as well.

You probably already noticed it, but don't forget to add "index." to that. I thought you were only looking for an html file and missed the fact that you need "index.html"

grep ^A.*index.html$

cat index_A | sed '/^A.*index\.html/!d'

Consider that the index_A file is having the following content.
A /test/test1/qa/test2/index.html
A /test/test1/qa/test3/test.jpg
A /test/test1/qa/test3/test1.jpg
A /test/test1/qa/test4/test.swf

So the sed will search for that pattern and it will not delete that line.
Other lines will be deleted. So we can get.

It is good practise to use quoting in this example to avoid possible unexpected expansion by the shell:

grep "^A.*index\.html$" infile