"In" in your first sentence -- "Many hostages hadn't eaten in days and were immediately given dinner, Russian Television reported" – can be interchanged with "for."
Michael Swan explains in Practical English Usage*:
"After negatives and superlatives, 'in' can also be used to talk about duration. This is especially common in American English.
I haven't seen him for/in months.
It was the worst storm for/in ten years."
Your sentence # 1 fits this category; "for" could be used interchangeably with "in.'
However, your sentence # 4 does NOT fit this category. If the sentence were negative, though, "in" could be used: "Rawlins worked out of Central Homicide BUT we HADN'T BEEN friends for/ IN years.
Sentences # 1, # 4, # 5, and # 6 all measure the duration of a time period. "For" indicates the duration of time in all tenses, but "in" can measure the duration of time only in some circumstances, in your sentence # 1, but not in # 4 as you have written it. Sentences # 5, or # 6 refer to the future, and "in" can not measure duration of time for the future.
When referring to the future, the prepositions "in" and "for" have different meanings. Take, for example, "I'll be home in two weeks," "I should be home in two weeks," and "I'm going to be home in two weeks." These sentences mean that in two weeks from today (December 18, 2003) -- on January 1, 2004 -- I'll begin my home visit. "In" + a future time expression refers to the beginning point at which something will begin, but it does not indicate the length of the activity, in this case the visit.
"I'll be home for two weeks," "I should be home for two weeks," and "I'm going to be home for two weeks," mean that the speaker will be home for a period of two weeks at some time in the future; "for" indicates the length of stay, but it doesn't tell when that stay will be. Your sentences #5 and # 6 fit this category. In #5, the issue will last "for years to come," and in # 6, the virus can survive "for years." "In" would not work to measure the time in these sentences.
You could, however, use "in" in # 5 not to indicate duration, but to indicate "during" or "within" this time period. In # 6, if the phrase were "in years to come," "in" would also be permissible to mean "during" or "within" this time period.
In your sentence # 2, "in" means "within" a time period, that is, before a certain time has passed. "For" can not be substituted here as it has a different meaning: to measure an entire period of time.
In your sentence # 3, "for the first time" and "for the last time" are set expressions; "in" can not be substituted.
*Practical English Usage, by Michael Swan. Oxford University Press, Second Edition. 1995