files=`git ls-files | grep -e '.*\.\(cc\|cpp\|hpp\|cppm\)' | grep -v 'tpls/'`
echo "" &> diff_files
echo "" &> clean_files
echo "" &> updated_files
tmp=`cat scripts/new_header | wc -l`
NNEW=$(($tmp))
tmp=`cat scripts/old_header | wc -l`
NOLD=$(($tmp))
NOLD1=$(($NOLD+1))
for file in $files; do
  head -n +$NOLD $file &> header
  diff header scripts/old_header &> old_header_diff
  count=`cat old_header_diff | wc -l`
  #echo $file " " COUNT " " $count >> diff_headers
  if [ "$count" -eq "0" ]; then
    echo $file >> clean_files
    cat old_header_diff >> clean_files
    { head -n +$NNEW scripts/new_header; tail -n +$NOLD1 $file; } > tmp
    cp tmp $file
  else
    head -n +$NNEW $file &> header
    diff header scripts/new_header &> new_header_diff
    count=`cat new_header_diff | wc -l`
    if [ "$count" -eq "0" ]; then
      echo $file >> updated_files
    else
      echo $file >> diff_files
      #cat header_diff >> diff_files
      tr -d '\n' < diff_files  | sed 's|\.\/| |g' &> modify_files
    fi
  fi
done
