#!/bin/bash
s='NULL	NULL	NULL'
sed -E ':a; s/(\t|^)NULL(\t|$)/\1\\N\2/g; ta' <<< "$s"
sed -E ':a; s/(\t|^)NULL(\t|$)/\1\\N\2/g; ta' <<< "NULL"