comparing lines from 2 files

Hi Friends,
I have 2 files A and B . I want to compare the 3rd line of file A and B .
(I dont want to compare the 2 files, using diff or cmp). I just want to know whether 3rd line of A matches the 3 rd line of B. Can anybody share their knowledge on the same?

Thanks ,
Vijaya

third_lne_A=`sed -n '3{p;q;}' fileA'
third_lne_B=`sed -n '3{p;q;}' fileB'
if [ "$third_lne_A" = "third_lne_B" ]; then
      echo "Same..."
fi

Dear anbu23,
can you please mention that in this line
third_lne_A=`sed -n '3{p;q;}' $FILENAME1`

what does {p;q;} mean?
the code is working properly.but please let me know {p;q;}

Thankx
Regards,
Pankaj

3 - line number
p - print command
q - quit command

3{p;q;} If the current line is third line in the file, then print that line and quit sed command. For example if your file has 50,000 lines and if you dont provide quit command, sed will process all the lines in the file. If you use quit command, it will save time.

Thanx anbu for your quick reply and a nice explanation.

i also want to know that how can i compare field by fileld of two files, like File A and File B?
as you have compared the lines i want to compare the each and every fields of each line of both the file...

Thanks
Regards,
Pankaj

If you want to compare all the fields which means comparing whole line with other. If not can you give sample input and output required?

awk 'FNR == 3 && NR == FNR { line = $0; nextfile } 
     FNR == 3 { 
                 if (line==$0){
		     print "Line equal"
		 }
		 else {
		     print "Line not equal"
		 }                 
		}' file1 file2 

Dear anbu23,

suppose i have a file FILE A

xxx|yyy|zzz|rrr
rrr|ttt|yyy|uuu

another file i have FILE B

bbb|ppp|eee
hhh|jjj|kkk

like this.
i just want to compare 1st field of FILE A with 1st field of FILE B...
like that
if the all fields are matches it wiil print a success msg else it will throw an error...

Thanks
Regards,

awk -F"|" ' NR == FNR { arr[$1]=1; next } !arr[$1] { print "Errorr" ;exit } END { print "Success" } ' filea fileb

Thank you very much anbu23 for your reply but my requirement is something different.
its like

FILE A

223|xls file pattern|ABCD|UUU
245|yyy file mmm|TRHJ|ZZZ

FILE B

disa|yyy|555223
asdf|uuu|627245

now look the 1st field of FILE A is matching with the last 3 number of 3rd field of FILE B...
this is the thing i want to do...

223 == 555223
245 == 627245
i want to match like this...

Thanks
Regards,
Pankaj

awk -F"|" ' NR == FNR { arr[$1]=$1; next }; $3 !~ arr[$1]"$" { print;exit } END { print "Success" } ' filea fileb

dear anbu23,
thanks a lot...
but can you please explain me your code?

Thankx,
Regards,

Above code doesn't work. Try this

awk -F"|" ' NR == FNR { arr[$1]=1; next }; 
	    !arr[substr($3, length($3)-2)] { print "Error" ;exit } 
	    END { print "Success" } 
' filea fileb

NR == FNR { arr[$1]=1; next } Keep first field as index and assign one to it. This block is executed till the end of first file.

!arr[substr($3, length($3)-2)] { print "Error" ;exit } Get the last three digit of third field and check whether it is an index in array arr. If not exit the processing.