Ich möchte, ob unter Shell-Skript wissen, kann weiterVereinfachen der Bash-Shell-Skript-Schleife
#!/bin/bash
a11=`cat CONTCAR | head -5 | tail -3 | head -1 | awk '{print $1}'`
a12=`cat CONTCAR | head -5 | tail -3 | head -1 | awk '{print $2}'`
a13=`cat CONTCAR | head -5 | tail -3 | head -1 | awk '{print $3}'`
b21=`cat CONTCAR | head -5 | tail -3 | head -2 | awk '{print $1}'`
b22=`cat CONTCAR | head -5 | tail -3 | head -2 | awk '{print $2}'`
b23=`cat CONTCAR | head -5 | tail -3 | head -2 | awk '{print $3}'`
c31=`cat CONTCAR | head -5 | tail -3 | head -3 | awk '{print $1}'`
c32=`cat CONTCAR | head -5 | tail -3 | head -3 | awk '{print $2}'`
c33=`cat CONTCAR | head -5 | tail -3 | head -3 | awk '{print $3}'`
[Bearbeiten] Ihre Frage etwas prägnant, prüfbare Abtastwerteingang (Inhalt von 'CONTCAR') aufzunehmen und erwartete Ausgabe und jemand wird Ihnen zeigen, wie es zu tun * * viel ** einfacher und ohne Schleife. Lesen Sie auch [why-is-using-a-shell-loop-to-process-text-betrachtet-schlechte-praxis] (http://unix.stackexchange.com/questions/169716/why-is-using-a- shell-loop-to-process-text-betrachtet-schlechte-praxis) –
Wow, Stéphane Chazelas Antwort in der oben genannten Frage von @ EdMorton ist ein erstaunliches Muss gelesen, perfekt für diese Frage. –
'Katze CONTCAR | Kopf -5 | Schwanz -3 | Kopf -1 | awk '{print $ 1}' 'ist genau äquivalent zu' awk 'NR == 3 {print $ 1}' CONTCAR' –