Search and print in Unix

Hi All
I have two files name file1 and file2

The date present in file1 is
aaaa
ssss
dddd

ffff
qqqq
wwww

eeee

and the data present in file2 is 
aaaa 1 2 3 4
ssss 3 5 6 7
dddd 1 2
qqqq 1 6 y 9 


I want to compare two files file1 and file2
The data present in file1 should be searched in file2 and if found it should be dispalyed

The output file wanted is

aaaa 1 2 3 4
ssss 3 5 6 7
dddd 1 2

ffff
qqqq 1 6 y 9 
wwww

eeee

Does your system have the "join" command? If not, there is a fairly simple solution with awk.

No Join working

Please check your example thoroughly. Where do the blank lines and the ffff , eeee and wwww lines come from ?

Bearing in mind you previous history of abstract posts, please post what Operating System and version you are running, and what Shell or other language you are using today.

Please post your attempt at the solution.

The Blank lines where present should be consider because it is part of data
My Operating sysyem is ubuntu 12.10
And using bash shell

In that case, I can't see the rule to get from input data to output data.
Please show your attempt . It might tell us what you are trying to achieve. The join command has been suggested, but it will not deal with the blank lines because they make the input file non-sorted.

awk -F" ", 'NR==FNR{a[$1]++;next} (a[$1])' file2 file1

and also
trying to do

cat file2 | while read line
do
#echo $line
grep -c $line file1
done

A Shell approach. The big issue is the blank lines:

(
cat file1|while read line1
do
        # Avoid feeding blank to grep
        if [ "${line1}""X" = "X" ]
        then
                echo "${line1}"
                continue
        fi
        # Does key exist in file2 ? 
        found=""
        found=$(grep \^"${line1}" file2)
        if [ ! "${found}""X" = "X" ]
        then
                echo "${found}"
        else
                echo "${line1}"
        fi
done
) > file3

./scriptname
cat file3
aaaa 1 2 3 4
ssss 3 5 6 7
dddd 1 2

ffff
qqqq 1 6 y 9 
wwww

eeee

This does not describe the process correctly.

Update file1 with the data from file2 using each file1 record as the matching key and output the results to file3.

Can you please explain the line5

if [ "${line1}""X" = "X" ] 

It's just avoiding the Shell syntax error if the input is blank by appending a string (in this case the character "X") to the input string.
There are other ways of achieving the same effect, but this technique works in every Bourne-type Shell.

I think you need an awk solution like this:

awk 'NR==FNR { a[$1]=$0;next} { if (a[$1]) print a[$1]; else print $0; }' file2 file1