gpt4 book ai didi

linux - 在标题中搜索模式并打印整列

转载 作者:太空宇宙 更新时间:2023-11-04 10:31:35 24 4
gpt4 key购买 nike

NAME    10/01   09/02   09/07   09/08   09/09   09/10   09/11   09/12   09/13   09/14   09/15   09/16   09/17   09/18   09/19   10/01
CNMPMT_DATA 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22
DATA01 9.79 10.75 13.67 7.97 15.22 15.1 14.63 15.71 15.56 15.37 16.69 17.33 17.06 16.5 18.01 99.22
DATATBLS4PEAS 9.21 7.45 51.77 8.26 54.56 54.43 50.68 42.2 38.23 53.47 51.02 49.53 48.01 46.58 46.34 99.22
EDD_DATA 57.79 57.71 58.46 57.58 57.93 59.09 58.88 58.88 58.83 58.79 58.77 58.73 58.7 59.69 59.34 99.22
EDD_INDX 23.34 23.44 22.96 23.27 23.07 22.94 22.79 22.94 23.06 23.03 23.13 23.25 23.08 22.81 23.05 99.22
INDX01 8.59 8.74 8.68 8.72 8.94 8.71 8.46 8.78 8.87 8.82 9.19 9.41 9.21 8.86 9.38 99.22
SYSAUX 96.65 96.67 96.62 96.92 96.55 96.57 96.56 96.59 96.57 96.63 96.65 96.7 96.72 96.73 96.65 99.22
SYSTEM 93.37 93.37 93.36 93.38 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 99.22
TEMP 97.43 98.50 98.54 88.77 99.54 95.68 99.54 99.52 99.25 99.35 96.44 98.87 98.53 98.54 98.13 99.22
TEMP_EDDDATA 96.58 96.58 96.58 96.58 96.58 96.58 96.58 96.55 96.55 96.55 96.55 96.54 96.37 96.37 96.38 99.22
UNDOTBS1 22.35 14.31 34.18 30.17 5.37 8.94 17.08 17.43 14.7 22.96 11.99 7.83 .02 8.07 3.67 99.22
UNDOTBS2 42.45 47.22 53.84 43.96 25.77 36.5 40.05 28.89 27.75 26.86 23.4 22.86 .02 .03 6.56 99.22
UNDOTBS3 68.65 72.3 39.89 28.95 44.52 69.05 71.89 52.23 48.23 41.67 31.52 30.09 16.98 23.44 18.54 99.22
USERS 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 99.22

这个文件我只想要九月份的列。文件以制表符分隔。尝试低于它的工作但它改变了列位置

awk 'NR==1{for(i=1; i<=NF; i++) if ($i ~"09") {a[i]++;} } { for (i in a) printf "%s\t", $i; printf "\n"}' Allen_Free.txt


09/07 09/08 09/09 09/10 09/11 09/12 09/13 09/14 09/15 09/16 09/17 09/18 09/19 09/02
99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22
13.67 7.97 15.22 15.1 14.63 15.71 15.56 15.37 16.69 17.33 17.06 16.5 18.01 10.75
51.77 8.26 54.56 54.43 50.68 42.2 38.23 53.47 51.02 49.53 48.01 46.58 46.34 7.45
58.46 57.58 57.93 59.09 58.88 58.88 58.83 58.79 58.77 58.73 58.7 59.69 59.34 57.71
22.96 23.27 23.07 22.94 22.79 22.94 23.06 23.03 23.13 23.25 23.08 22.81 23.05 23.44
8.68 8.72 8.94 8.71 8.46 8.78 8.87 8.82 9.19 9.41 9.21 8.86 9.38 8.74
96.62 96.92 96.55 96.57 96.56 96.59 96.57 96.63 96.65 96.7 96.72 96.73 96.65 96.67
93.36 93.38 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.37
98.54 88.77 99.54 95.68 99.54 99.52 99.25 99.35 96.44 98.87 98.53 98.54 98.13 98.50
96.58 96.58 96.58 96.58 96.58 96.55 96.55 96.55 96.55 96.54 96.37 96.37 96.38 96.58
34.18 30.17 5.37 8.94 17.08 17.43 14.7 22.96 11.99 7.83 .02 8.07 3.67 14.31
53.84 43.96 25.77 36.5 40.05 28.89 27.75 26.86 23.4 22.86 .02 .03 6.56 47.22
39.89 28.95 44.52 69.05 71.89 52.23 48.23 41.67 31.52 30.09 16.98 23.44 18.54 72.3
22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09

09/02 应该先出现,然后是 09/07 不确定是什么问题。

请帮忙。

最佳答案

如果 perl 解决方案没问题,

$ perl -MList::MoreUtils=indexes -nale '@i = indexes { /^09/ } @F if $. == 1; print join "\t", @F[@i]' ip.txt 
09/02 09/07 09/08 09/09 09/10 09/11 09/12 09/13 09/14 09/15 09/16 09/17 09/18 09/19
99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22 99.22
10.75 13.67 7.97 15.22 15.1 14.63 15.71 15.56 15.37 16.69 17.33 17.06 16.5 18.01
7.45 51.77 8.26 54.56 54.43 50.68 42.2 38.23 53.47 51.02 49.53 48.01 46.58 46.34
57.71 58.46 57.58 57.93 59.09 58.88 58.88 58.83 58.79 58.77 58.73 58.7 59.69 59.34
23.44 22.96 23.27 23.07 22.94 22.79 22.94 23.06 23.03 23.13 23.25 23.08 22.81 23.05
8.74 8.68 8.72 8.94 8.71 8.46 8.78 8.87 8.82 9.19 9.41 9.21 8.86 9.38
96.67 96.62 96.92 96.55 96.57 96.56 96.59 96.57 96.63 96.65 96.7 96.72 96.73 96.65
93.37 93.36 93.38 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36 93.36
98.50 98.54 88.77 99.54 95.68 99.54 99.52 99.25 99.35 96.44 98.87 98.53 98.54 98.13
96.58 96.58 96.58 96.58 96.58 96.58 96.55 96.55 96.55 96.55 96.54 96.37 96.37 96.38
14.31 34.18 30.17 5.37 8.94 17.08 17.43 14.7 22.96 11.99 7.83 .02 8.07 3.67
47.22 53.84 43.96 25.77 36.5 40.05 28.89 27.75 26.86 23.4 22.86 .02 .03 6.56
72.3 39.89 28.95 44.52 69.05 71.89 52.23 48.23 41.67 31.52 30.09 16.98 23.44 18.54
22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09 22.09
  • -MList::MoreUtils=indexes 使用 List::MoreUtils 中的 indexes 函数模块
  • -ale 在空格处分割输入行并保存到@F数组,输入行中的换行符在打印时被剥离并添加
  • @i = indexes {/^09/} @F if $. == 1 如果是第一行,则获取 @F 数组中与正则表达式 /^09/
  • 匹配的所有元素的索引
  • print join "\t", @F[@i] 打印保存在@i数组中的@F匹配索引的元素, 由制表符分隔

如果 List::MoreUtils 模块不可用,

perl -nale '@i = grep { $F[$_] =~ /^09/ } 0..$#F if $. == 1; print join "\t", @F[@i]' ip.txt

关于linux - 在标题中搜索模式并打印整列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com