------------------------------------------------------------------------ finding "the the" even when spit across two lines ------------------------------------------------------------------------ gsed -n '1{h;d;};1!{H;x;s/ *the *the/ the /;s/ *the *\n *the */ the\n/;P;s/^.*\n//;x;}' kitty.txt