awk 'BEGIN { FS=OFS="=" } $1 == "$$STATE" { split($2,a," "); $2 = "'"'"'" a[1] "'"'"'" } 1' file
This uses awk
to parse the file as a collection of =
-delimited fields. If the first field is the exact string $$STATE
, then the second field is split on spaces and assigned the value of its first space-delimited bit, with single quotes around it.
The funky looking "'"'"'"
is a double quoted single quote character within a single quoted awk
script.
The result would be
$$BATCHCTRL=TEST-012017
$$STATE='CA'
$$FROM_DATE=01/10/2017
$$TO_DATE=01/30/2017
Alternatively, with sed
:
sed -E '/^\$\$STATE=/s/=([^ ]*).*/='"'"'\1'"'"'/' file
This would locate any line that starts with the string $$STATE=
and then replace anything after the =
with the first bit before a space, again with single quotes inserted.