Using first word and print their contents using awk

suppose u hava a file
G1354R tGGC-CGC
D1361N cGAC-AAC
I1424T ATC-ACC
R768W gCGG-TGG
Q1382R CAG-CGG
Q178E gCAG-GAG
Y181C TAC-TGC
.........cont.
So the question is
By searching for first word i.e.character say R
output shud be
R768W gCGG-TGG
R182P CGG-CCG
R189W gCGG-TG
if Q then
Q1382R CAG-CGG
Q178E gCAG-GAG
So.... continue with all characters .i.e. first word ..

Thanks

try this out,

awk '/^Q/ {print $0}' <<file name>>

Q1382R CAG-CGG
Q178E gCAG-GAG

grep '^Q' filename

What about if you need to extract the lines based on 5th charater in first word.

do this-

awk 'BEGIN{FS=" "}{if ( substr($1,5,1) == "Q" ) print $0}' file

cheers,
Devaraj Takhellambam

Or:

grep ^....Q filename

With awk it would be:

awk '/^....Q/' filename

Hi,
This one should be ok.

a=1;
while [ $a -le 1 ]
do
	echo "please input the character you would like to search,XX for exit"
	read var
	if [ $var = "XX" ]
	then
		a=2
	fi
	cat a | sed -n "/^$var/p"
done