gpt4 book ai didi

linux - 如何在 bash 中使用 'while ..; do..; done'

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:06:52 27 4
gpt4 key购买 nike

<分区>

我在 bash 中使用此命令执行操作时遇到问题。以下是我所拥有的:

cat namelist | while read line; do awk '$1 == $line {print $0}' Jan.txt; done

namelist 是一个不重复的名单,每一行都有每个名字。而 Jan.txt 是这样的信息文件:

ermartin pts/10       Tue Jan 19 09:49 - 10:15  (00:26)     171.66.208.139
sdou pts/6 Tue Jan 19 01:52 - 22:20 (9+20:27) 131.243.186.99
sdou pts/2 Tue Jan 19 01:20 - 22:20 (9+20:59) 131.243.186.99
phu pts/2 Sat Jan 16 12:21 - 15:13 (02:52) lbl-ipsec-7667.dhcp.lbl.gov
phu pts/2 Sat Jan 16 10:07 - 12:01 (01:54) lbl-ipsec-7622.dhcp.lbl.gov
sjames pts/5 Fri Jan 15 12:06 - 13:06 (01:00) lakshmi.lbl.gov
ermartin pts/2 Fri Jan 15 08:36 - 12:43 (04:07) 171.66.208.134
ermartin pts/2 Fri Jan 15 08:31 - 08:36 (00:05) 171.66.208.134
camitche pts/4 Thu Jan 14 15:18 - 20:47 (05:28) 171.66.208.134
ermartin pts/2 Thu Jan 14 13:20 - 15:57 (02:36) 171.66.208.139
ermartin pts/2 Thu Jan 14 12:35 - 13:00 (00:25) 171.66.208.139
sjames pts/2 Thu Jan 14 06:17 - 06:27 (00:09) phys1.als.lbl.gov
sjames pts/2 Thu Jan 14 06:17 - 06:17 (00:00) phys1.als.lbl.gov
ermartin pts/0 Wed Jan 13 15:19 - 15:50 (00:31) 171.66.208.139
ermartin pts/0 Wed Jan 13 07:55 - 08:09 (00:13) c-24-130-14-154.hsd1.ca.comcast.net

我只是试图将 namelist 中的名称与该文件匹配,然后对该文件中的每一行信息执行操作,但是当我执行 $1 == $line,它说这是一个错误。如何正确使用此命令?

是否也可以遍历月份并将它们打印为标题,如下所示:

[Jan] 
sjames ...hours
sdou ...hours

[Feb]
sjames ...hours
sdou ...hours

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