作为我学位课程的一部分,我必须使用输出大数据点列表的软件。我遇到的问题是它以这样的方式输出它我无法绘制它(不是没有先手动格式化它)。原始输出如下所示:
kpt# 1, nband= 30, wtk= 1.00000, kpt= 0.0000 0.0000 0.0000 (reduced coord)
-3.34630 -3.17801 -3.09372 -3.02971 -3.02971 -2.99649 -2.99399 -2.92282
-2.83147 -2.83147 -1.71295 -1.43814 -1.43814 -1.35290 -0.76039 -0.68874
-0.63265 -0.62874 -0.62874 -0.41856 -0.19886 -0.19886 -0.18178 -0.08505
-0.01900 0.03106 0.03140 0.03140 0.04786 0.07255
kpt# 2, nband= 30, wtk= 1.00000, kpt= 0.0101 0.0101 0.0000 (reduced coord)
-3.28432 -3.17790 -3.09155 -3.01881 -3.00521 -2.99279 -2.98718 -2.91048
-2.83086 -2.83038 -1.71286 -1.43814 -1.43810 -1.35288 -0.75994 -0.68868
-0.63260 -0.62875 -0.62873 -0.41848 -0.19909 -0.19886 -0.18140 -0.08502
-0.01886 0.02667 0.03126 0.03590 0.04781 0.07262
.
.
.
kpt# 3, nband= 30, wtk= 1.00000, kpt= 0.0202 0.0202 0.0000 (reduced coord)
-3.25059 -3.17763 -3.08747 -3.03929 -3.00146 -2.99159 -2.96062 -2.89743
-2.83133 -2.83014 -1.71274 -1.43817 -1.43810 -1.35287 -0.75943 -0.68865
-0.63250 -0.62885 -0.62877 -0.41829 -0.19976 -0.19888 -0.18036 -0.08499
-0.01851 0.02198 0.03084 0.04028 0.04753 0.07283
kpt# 4, nband= 30, wtk= 1.00000, kpt= 0.0303 0.0303 0.0000 (reduced coord)
-3.25108 -3.17577 -3.08771 -3.04025 -3.00164 -2.98867 -2.96080 -2.89726
-2.83695 -2.83100 -1.71270 -1.43829 -1.43819 -1.35287 -0.75914 -0.68881
-0.63236 -0.62892 -0.62883 -0.41799 -0.20076 -0.19897 -0.17884 -0.08492
-0.01820 0.01707 0.03016 0.04442 0.04683 0.07314
基本上我需要一个bash脚本来将所有数字列表放在每行以'kpt#'开头的行之间,删除以'kpt#'开头的行并将行号放在每行的开头就像这样:
1 -3.34630 -3.17801 -3.09372 -3.02971 -3.02971 -2.99649 -2.99399 ...
2 -3.28432 -3.17790 -3.09155 -3.01881 -3.00521 -2.99279 -2.98718 ...
3 -3.25059 -3.17763 -3.08747 -3.03929 -3.00146 -2.99159 -2.96062 ...
这将允许我立即绘制它!任何帮助都非常感激。干杯 杰克M
答案 0 :(得分:2)
假设您的数据位于名为data.txt
grep -v 'kpt#' data.txt | nl -nln
grep -v
删除标题行,nl -nln
将左对齐数字添加到行中。
答案 1 :(得分:1)
如果 awk 可以接受:
awk 'END {
print kpt, r
}
/kpt#/ {
if (kpt)
print kpt, r
r = x
sub(/,.*/, x, $2)
kpt = $2
next
}
{
r = r ? r FS $0 : $0
}' infile
答案 2 :(得分:0)
使用sed
sed 's/^kpt# *\([0-9]*\).*$/\1/' input | sed 'N;N;N;N;s/\n/ /g'