data processing

hi
i am having a file of following kind:

20015#67143645#143123#4214
62014#67143148#67143159#456
15432#67143568#00143862#4632
54112#67143752#0067143657#143
54623#67143357#167215#34531
65446#67143785#143598#7456
75642#67143546#156146#845
24464#67143465#172532#6544
58413#67143213#0159486#465
56431#67143875#143854#456
76423#67143534#00143888#154

i have been asked to extract all lines having any occurence of 143 in 3rd field. the output file must have an occurence of 143 in third field.
considering the above file my output should be :

20015#67143645#143123#4214
62014#67143148#67143159#456
15432#67143568#00143862#4632
54112#67143752#0067143657#143
65446#67143785#143598#7456
56431#67143875#143854#456
76423#67143534#00143888#154

How about

sed -n -e "s_[^#]*#[^#]*#[^#]*143.*_&_p" in.txt

Or:

awk -F# '{if ($3 ~ /143/) print $0;}' mydata.txt

hi vino

could u explain me the working of ur command.

Regards
Rochit

sed -n -e "s_[^#]*#[^#]*#[^#]*143.*_&_p" in.txt

-n : do not print the lines that are read.

[^#]*# : Any non-# characters followed by any number of non-# characters till you reach the first occurence of #.

*143.* : a pattern which has 143 in it.

& : denotes whatever was captured in the pattern field of s/pattern/replacement/

p : print the line. This is needed because we used -n.

Thanks alot, i am getting same outputs using awk & sed.