fix missing dollar sign on shell variable and implement non-greedy match in sed