1

I have a file like this (tens of variables) :

PLAY="play"
APPS="/opt/play/apps"
LD_FILER="/data/mysql"
DATA_LOG="/data/log"

I need a script that will output the variables into another file like this (with space between them):

PLAY=${PLAY} APPS=${APPS} LD_FILER=${LD_FILER}

Is it possible ?

3 Answers 3

3

I would say:

$ awk -F= '{printf "%s=${%s} ", $1,$1} END {print ""}' file
PLAY=${PLAY} APPS=${APPS} LD_FILER=${LD_FILER} DATA_LOG=${DATA_LOG} 

This loops through the file and prints the content before = in a format var=${var} together with a space. At the end, it prints a new line.

Note this leaves a trailing space at the end of the line. If this matters, we can check how to improve it.

Sign up to request clarification or add additional context in comments.

Comments

1
< input sed -e 's/\(.*\)=.*/\1=${\1}/' | tr \\n \ ; echo

1 Comment

Interesting expression. Any reason for saying tr \\n \ instead of [more readable] tr "\n" " "?
0
sed 's/"\([^"]*"\)"/={\1}/;H;$!d
x;y/\n/ /;s/.//' YourFile

your sample exclude last line so if this is important

sed '/DATA_LOG=/ d
   s/"\([^"]*"\)"/={\1}/;H;$!d
   x;y/\n/ /;s/.//' YourFile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.