Replacing entire fields with specific text at end or beginning of field

Greetings.

I've got a csv file with data along these lines:

Spumoni's Pizza Place, Placemats n Things, Just Lamps
Counterfeit Dollars by Vinnie, Just Shades, Dollar Store

I want to replace the entire comma-delimited field if it matches something ending in "Place" or beginning with "Dollar", but not if those words are simply in the middle of the field. So the desired result would be something like:

SPECIAL, Placemats n Things, Just Lamps
Counterfeit Dollars by Vinnie, Just Shades, SPECIAL

How would I do this using awk, sed, csh, or whatever is the right tool for the task? Thanks!

Hi, if there are no TABS, try:

awk '{for(i=1; i<=NF; i++) if($i~/^ *Dollar|Place *$/) $i="SPECIAL"}1' FS=, OFS=, file

--
otherwise use $i~/^[ \t]*Dollar|Place[ \t]*$/

1 Like

Awesome, thanks, I get the premise!