display file where 4th field = 200704

Hello
I have a file which is pipe delimited.
The 4 th field has value like 200704 or 200705 etc.
Now i have to get only those records where 4th field is 200704
How can i do this?
I have to get the whole record where 4th field = 200704

try:

awk -F '|' '{ if($4 == "200704") { print } }' filename

not working. In the output file, for all the records, 4th field is replaced as 20074. But how can i search in the file

$ cat d
mark|64|200710|guitar
mike|61|200605|bass
pete|65|200704|drums
lisa|67|200705|vocals
$ awk -F '|' '{if($3=="200605") {print} }' d
mike|61|200605|bass
$

Works on my iMac OK. Did you use two equal signs in the test?

I have also tested this on test data, its working. But when i run the same on my data which has 90 fields in each record, if value is found it displays only 8 fields. The records is searched corectly, but when displaying many fields are truncated. Let me know if i have to add any code in this

raja this will work try it

grep "^[0-9a-zA-Z]*|[0-9a-zA-Z]*|[0-9a-zA-Z]*|[0-9a-zA-Z]*|2004" < test.txt >> test1.txt

raja this also works

cat one.txt | awk '{print $1;}' | awk -F"|" '{if($3==2004)print $0}'

Strange, the operation is: grep data and print unchanged lines. The short version:

awk -F'|' '$4==200704' file