Basically, its a game server (minecraft) and I have a situation where I am attempting to automate new world generation. Basically, I have a file that gets generated happily which has this snippet in it.file1.txtkeepSpawnInMemory: 'true'spawnLocation:  ==: MVSpawnLocation  yaw: 0.0  pitch: 0.0  z: 256.5  y: 62.0  x: -223.5autoLoad: 'true'bedRespawn: 'true'This works fine, but I need to extract the z: 256.5, y:62.0 and x: -223.5 respectively and then write a file called file2.txt with the following lines. world: mine x: -223.5 y: 62.0 z: 256.5 yaw: 0.0 pitch: 0.0 name: mineI assume I'll be using something like awk to extract the initial numbers, assigning them to variables then writing the file? I have never used awk before, and I am insanely confused. Appreciate any help in this guys. Im using Ubuntu linux, bash scripts. Can I extract text like that and make them into variables using awk and bash?EDIT:I did forget to mention that the file 1 has multiple instances of x,y and z. It can be accessed here: http://pastebin.com/TqaLcWzVIs there a way to start at a certain line? For example, z, y and x will always be on lines 183, 184 and 185 respectively.
Extracting text string from file, assigning them to variables then writing them to another file?
text processing;awk
Try this script:#!/bin/bashFILE1=/path/to/file1FILE2=/path/to/file2#extracting lines 183 to 185FILE1=$(awk 'FNR>=183&&FNR<=185' $FILE1)#extracting variables    Z=$(echo $FILE1 | grep z: | awk '{print $2}')Y=$(echo $FILE1 | grep y: | awk '{print $2}')X=$(echo $FILE1 | grep x: | awk '{print $2}')#YAW=$(echo $FILE1 | grep yaw: | awk '{print $2}')#PITCH=$(echo $FILE1 | grep pitch: | awk '{print $2}')cat <<EOF > $FILE2 world: mine x: $X y: $Y z: $Z yaw: 0.0 pitch: 0.0 name: mineEOFIf you want it to also extract the YAW and PITCH:Change the awk line to extract from line 181:FILE1=$(awk 'FNR>=181&&FNR<=185' $FILE1)Uncomment the YAW and PITCH linesChange the yaw: and pitch: at the very bottom to be:yaw: $YAWpitch: $PITCH