Skip to content

Instantly share code, notes, and snippets.

@singularitti
Last active April 8, 2019 02:32
Show Gist options
  • Save singularitti/14f387da77c223cf06b596d786b76f69 to your computer and use it in GitHub Desktop.
Save singularitti/14f387da77c223cf06b596d786b76f69 to your computer and use it in GitHub Desktop.
Grep final optimized cell from vc-relax #Shell #QE
#!/usr/bin/env bash
# Helpful guides: https://github.com/koalaman/shellcheck/wiki/SC1065
# and: https://superuser.com/questions/748724/pass-a-large-string-to-grep-instead-of-a-file-name
folders=()
if [ -f finalcell ]; then
rm finalcell
else
touch finalcell
fi
echo "# This is generated in directory $(pwd)" >finalcell
for folder in "$@"; do
[[ -d $folder ]] || break # handle the case of no vc_* folders
folders+=($folder)
done
for folder in "${folders[@]}"; do
(
cd "$folder" && echo "Current folder is: $folder" >>../finalcell || return
(
cd vc_relax && pwd || return
contents=$(awk "/Begin final coordinates/,/End final coordinates/" ./*.out)
GREP_COLOR='31;1' grep -E --color=always "new unit-cell volume.*" <<<"$contents"
grep "new unit-cell volume.*" <<<"$contents" >>../../finalcell
GREP_COLOR='36;1' grep -E --color=always -A 3 "CELL_PARAMETERS.*" <<<"$contents"
grep -A 3 "CELL_PARAMETERS.*" <<<"$contents" >>../../finalcell
GREP_COLOR='34;1' grep -E --color=always -A 2 "ATOMIC_POSITIONS.*" <<<"$contents"
grep -A 2 "ATOMIC_POSITIONS.*" <<<"$contents" >>../../finalcell
)
)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment