I have the line:
MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m
and want to convert it to (add quotation marks on field 2->n):
export MAVEN_OPTS="-XX:MaxPermSize=128m -Xms128m -Xmx768m"
I have the line:
MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m
and want to convert it to (add quotation marks on field 2->n):
export MAVEN_OPTS="-XX:MaxPermSize=128m -Xms128m -Xmx768m"
echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" | sed 's/=/="/; s/$/"/'
some awk possibilities (tested in ubuntu)
echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" | awk 'BEGIN{FS="MAVEN_OPTS="; OFS="MAVEN_OPTS=\""; ORS="\"\n"} {print $1,$2 }'
echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" | awk 'BEGIN{FS="MAVEN_OPTS="; OFS="MAVEN_OPTS=\"";} {print $1,$2 "\""}'
Another awk solution:
echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" |
awk -F= 'BEGIN {OFS=FS} {$2="\"" $2; $NF=$NF "\""; print}'
This is an another approach:
$ echo 'MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m' |
awk 'match($0,/=.*/)&&$0="export "substr($0,1,RSTART-1)"="substr($0,RSTART+1)'
If you have gawk:
$ echo 'MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m' |
gawk '$0=gensub(/^(.*)=(.*)/,"\\1=\\2",1)'