I am currently trying to grab the nth line of text out of a file namelist.txt, store it in a variable "name", and write it to EnergyData.txt using "head -n," as shown:
#!/bin/bash
counter=0
for folder in */
do
   counter=$((counter+1))
   name=$(cat namelist.txt | head -n $counter)
   echo $name
   printf $name >> EnergyData.txt
   cd $folder
   for i in */
   do
      cd $i
      ground_state=$(cat aims.out | grep  "Total energy of the DFT" | cut -c 77-94)
      HL_gap=$(cat aims.out | grep "Overall HOMO-LUMO gap" | tail -n 1 | cut -c 30-41 )
      echo "$i G1: $ground_state " >> ../../EnergyData.txt
      echo "$i HOMO-LUMO gap: $HL_gap "  >> ../../EnergyData.txt
      cd ..
   done
   cd ..
   min=$(cat EnergyData.txt | grep "G1" | cut -c 7-24 | sort -n | head -1)
   echo $min
   minline=$(cat EnergyData.txt | grep "$min" | cut -c 1-25 )
   echo -e "min energy: $minline\n" >> EnergyData.txt
done
Instead of grabbing just the nth line, it grabs the 1st-nth line, pasting progressively more lines as the loop continues. Any advice on how to fix this problem?
 
     
    