fork download
  1. #!/bin/bash
  2. file1='...
  3. bfgs converged in 9 scf cycles and 8 bfgs steps
  4. (criteria: energy < 6.0E-05 Ry, force < 1.0E-04 Ry/Bohr)
  5.  
  6. End of BFGS Geometry Optimization
  7.  
  8. Final energy = -1343.8825757257 Ry
  9. Begin final coordinates
  10.  
  11. ATOMIC_POSITIONS (angstrom)
  12. Fe 1.0730540812 3.7648438571 1.4484500000
  13. Fe 3.2976459188 0.6816561429 1.4484500000
  14. Fe 3.2584040812 2.9049061429 0.0000000000
  15. Fe 1.1122959188 1.5415938571 0.0000000000
  16. C 2.1853500000 2.2232500000 1.4484500000
  17. C 0.0000000000 0.0000000000 -0.0000000000
  18. End final coordinates
  19.  
  20.  
  21.  
  22. Writing output data file ./out/100Co2C.save/
  23.  
  24. init_run : 486.03s CPU 493.55s WALL ( 1 calls)
  25. ...'
  26. file2='...
  27. ATOMIC_SPECIES
  28. C 12.0107 C.pbesol-n-kjpaw_psl.1.0.0.UPF
  29. Co 58.933195 co_pbesol_v1.2.uspp.F.UPF
  30. Fe 55.845 Fe.pbesol-spn-kjpaw_psl.0.2.1.UPF
  31. ATOMIC_POSITIONS angstrom
  32. Co 1.0085465598 3.7287218832 1.4484500000
  33. Co 3.3775861828 0.7084455291 1.4484500000
  34. Fe 3.2243420022 2.9272726906 0.0000000000
  35. Co 1.1549449803 1.5394425244 0.0000000000
  36. C 2.1517221305 2.1838545768 1.4484500000
  37. C 0.0096081444 0.0285127960 0.0000000000
  38. K_POINTS crystal
  39. 388
  40. 0.0000000000 0.0000000000 0.0000000000 1
  41. ...'
  42. new_coords=$(sed -n '/Begin/,/End/{//b;p}' <<< "$file1")
  43. new_coords=$(echo "${new_coords//ATOMIC_POSITIONS (angstrom)}" | sed '/^$/d')
  44. old_coords=$(sed -n '/ATOMIC_POSITIONS/,/K_POINTS/{//b;p}' <<< "$file2")
  45.  
  46. quoteRe() { sed -e 's/[^^]/[&]/g; s/\^/\\^/g; $!a\'$'\n''\\n' <<<"$1" | tr -d '\n'; }
  47. quoteSubst() {
  48. IFS= read -d '' -r < <(sed -e ':a' -e '$!{N;ba' -e '}' -e 's/[&/\]/\\&/g; s/\n/\\&/g' <<<"$1")
  49. printf %s "${REPLY%$'\n'}"
  50. }
  51.  
  52. sed -e ':a' -e '$!{N;ba' -e '}' -e "s/$(quoteRe "$old_coords")/$(quoteSubst "$new_coords")/" <<< "$file2"
Success #stdin #stdout 0.02s 5560KB
stdin
Standard input is empty
stdout
...
ATOMIC_SPECIES
C      12.0107 C.pbesol-n-kjpaw_psl.1.0.0.UPF
Co     58.933195 co_pbesol_v1.2.uspp.F.UPF
Fe     55.845 Fe.pbesol-spn-kjpaw_psl.0.2.1.UPF
ATOMIC_POSITIONS angstrom
Fe            1.0730540812        3.7648438571        1.4484500000
Fe            3.2976459188        0.6816561429        1.4484500000
Fe            3.2584040812        2.9049061429        0.0000000000
Fe            1.1122959188        1.5415938571        0.0000000000
C             2.1853500000        2.2232500000        1.4484500000
C             0.0000000000        0.0000000000       -0.0000000000
K_POINTS crystal
388
    0.0000000000     0.0000000000     0.0000000000 1
...