how to assign first img linked on a node to image field What I have: a D7 site with around 2k nodes on it, many of these nodes have images &lt;img&gt; in the html of the body but those images are not assigned to the image field. (It is an old drupal site that was upgraded to D7).

I would like to parse all the nodes so that the first image in the body content is assigned programatically to the image field of the node. Manually editing is not an option, as there are over 2.000 nodes on that site.

Is there a way to do that programatically? I guess field api may help (and so my tag) but I dont really know.

Thanks.
I would write a module that read the field_data_body table in database. This table contains a field called body_value where the values are stored. If the module find a  mark, you can get the "src" attributte. 

You don't forget to make a comparison in field_revision_body table to avoid problems.

Once you have the path of the file, you must save it as managed file in database. For this, take a look to "file.inc".

Here a little summary for last changes in D7. 

I think it's important that you understand the difference between managed files and unmanaged files. Once you have saved the file, you could load the node, and assign to the field_image field, then node_save().