I am having trouble using this command in bash to do the operation. The following is what I have:
cat namelist | while read line; do awk '$1 == $line {print $0}' Jan.txt; done
The namelist
is a unrepeated namelist with each name on each line. And Jan.txt is a file of information like these:
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
I am just trying to match names in namelist
to this file and then do the operation to each line of the information in this file but when I did $1 == $line
, it says it's an error. How do I make use of this command properly?
Is it possible to also loop over the Months and print them as a title so like:
[Jan]
sjames ...hours
sdou ...hours
[Feb]
sjames ...hours
sdou ...hours