Here is some code snipets:
Reading an attribute to a variable:
attvar = &attvl(part,'attribute_name',iferr,l00

Replace attribute_name with your attribute. You can use an array in a loop.
Create a text file:
create/txt,10,'text_file_name.txt',iferr,err0:
Writing a line of data to a text file:
Format mask
fmt1='#@@@@@@@@ #@@@@@@@@@@@@@@@@@ #@@@@@@@@@@@@'
write/10,using,fmt1,attr1, attr2, attr3
file/txt,10
"Wildfires are dangerous, hard to control, and economically catastrophic."
Ben Loosli
CAD/CAM System Analyst
Ingersoll-Rand