Here is my file contents:
I wish to generate <value-in-name-tag>.cfg which should contain entries like below
Currently i am able to populate only what you see below.
How can i also populate
in the .cfg files ?
Below is my code so far:
grep -o '<name>.*</name>' deploy.tmp | sed 's/\(<name>\|<\/name>\)//g' | while IFS= read -r entry; do
echo "APP_NAME=$entry" > $entry.cfg
done
Hello mohtashims,
Could you please try following and let me know if this helps you.
awk -F"[><]" '/^<name>/{Q="";W=$3;getline;Q="APP_NAME=" W;getline;Q=Q?Q ORS "MOD_TYPE="$3:"MOD_TYPE="$3;getline;print Q > W;}' Input_file
Output files will be as follows.
cat cert
APP_NAME=cert
MOD_TYPE=war
cat Security
APP_NAME=Security
MOD_TYPE=ear
EDIT: Adding a non-one liner form of same now.
awk -F"[><]" '/^<name>/{
Q="";
W=$3;
getline;
Q="APP_NAME=" W;
getline;
Q=Q?Q ORS "MOD_TYPE="$3:"MOD_TYPE="$3;
getline;
print Q > W;
}
' Input_file
Thanks,
R. Singh