I have a simple loop that reads an input file (.xyz) line-by-line and echoes it into an output file (.gjf). However I want it to terminate once it encounters a line only containing "Bonds" so that only the initial part of the input file is copied into the output file.
I am doing this for many input/output files (hence ${i} as the filenames) so the number of lines copied over may not be the same, but will all contain a line with "Bonds" at some point. This is why I need to read line-by-line.
The code below will echo into the output file correctly, but won't exit the while loop when it encounters "Bonds", instead copying over the entire input file. Is the output of read -r not treated as a string?
while read -r LINE ; do
if [[ "$LINE" == "Bonds" ]] ; then
break
else
echo "$LINE" >> "${i}.gjf"
fi
done < "./${i}.xyz"
Below is an example of the input (.xyz) file:
0 2
6 0.097055000 -1.260034000 1.473340000
6 0.336623000 -0.000274000 0.631466000
1 0.279787000 -2.153356000 0.870406000
1 -0.939049000 -1.279769000 1.829917000
1 0.757490000 -1.287905000 2.345029000
Bonds
1 2 S
1 3 S
1 4 S
1 5 S
2 6 S
I would only like the lines above "Bonds" to be copied. I am new to bash, so some guidance would be appreciated. Thanks.