tags:

views:

412

answers:

4

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"
A: 
echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" | sed 's/=/="/; s/$/"/'
seb
A: 

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 "\""}'
Sathya
A: 

Another awk solution:

echo "MAVEN_OPTS=-XX:MaxPermSize=128m -Xms128m -Xmx768m" |
awk -F= 'BEGIN {OFS=FS} {$2="\"" $2; $NF=$NF "\""; print}'
glenn jackman
A: 

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)'
Hirofumi Saito