Rather than write the code for you, I thought it would be useful to explore in general terms how we go about solving this type of problem.
What you want to do is parse a file: a very common operation in bioinformatics. So common in fact, that you will often find that someone has done the work for you. I'll come back to that briefly at the end of the answer.
Here are the steps involved in developing a parser.
First, understand the structure of the file - in your case, a PDB file. This is achieved by reading documentation and by examining the file yourself in e.g. a text editor. Knowing that PDB files come from the Protein Data Bank, a web search should lead you to the appropriate documentation.
Second, identify the sub-parts of the file that you want to extract. Try to determine what makes them distinct from other parts of the file. When you look at a PDB file, you'll see that the parts containing coordinates look like this:
ATOM 834 CD2 TYR A 108 2.688 48.014 2.423 1.00 13.01 C
HETATM 968 CU CU1 A 201 16.622 34.752 4.635 0.90 18.04 CU
Try to explain in words what you see. You might say something like "line starts with ATOM or HETATM, followed by several space-separated fields, of which columns 7, 8 and 9 are X, Y and Z coordinates."
Third, without writing any code, describe how you would process the file to extract only those parts that interest you. Be precise and detailed. For example:
- open the file
- read one line at a time
- does the line begin with ATOM or HETATM?
- if so, split the line on space
- print out only the fields with X, Y and Z
Finally, you are ready to write your code. What you wrote in step 3 is a guide to the methods that you need to learn (if you don't know them already) in your chosen programming language. So you need to know how to open a file for reading, scan one line at a time, match patterns to a line, split lines into arrays and print out the correct array elements.
And that is how you write a parser.
However - there's often no need to reinvent the wheel. There is a format called "XYZ" which is essentially just the coordinates and a web search for "convert PDB to XYZ" is sure to throw up a few tools. And don't be tied to one language if a good solution is available in another - such as this Python PDB->XYZ converter.