I am looking to automate something with a script in bash or python.
Let's say I have a config file from a device. A simple config.txt file. Content could be like this (actual file is much longer and has much more text):
> cat config.txt > > ASA Version 9.1(5) > ! > terminal width 511 > hostname confidential > domain-name confidential > enable password encrypted > passwd encrypted > names > ! > interface GigabitEthernet0/0 > nameif interconnection > security-level 50 > ip address 184.108.40.206 255.255.255.240 standby 220.127.116.11 > ! > interface GigabitEthernet0/1 > description Trunk > no nameif > no security-level > no ip address > ! > interface GigabitEthernet0/1.4 > description confidential > vlan 4 > nameif vlan004_confidential > security-level 50 > ip address 18.104.22.168 255.255.255.0 > ! > object network confidential > host 22.214.171.124 > object network confidential2 > host 126.96.36.199 > object network confidential3 > host 188.8.131.52 >! >access-list vlan65_access_in extended permit object-group confidential any object-group confidential >access-list vlan65_access_in remark Allow ICMP OK-20131105 >access-list vlan65_access_in extended permit icmp any object vlan48-confidential >access-list vlan65_access_in remark Allow NTP OK-20131105 >access-list vlan65_access_in extended permit udp any object-group confidential eq ntp >access-list warehouse_access_in remark Access to confidential >access-list warehouse_access_in extended permit object-group confidential any object-group confidential >access-list warehouse_access_in remark Access to DNS srvrs >access-list warehouse_access_in extended permit ip any object-group DNS_Servers >access-list warehouse_access_in remark Allow acces to AD >! >no pager >logging enable >logging timestamp >logging standby >logging list SysLogs message 304001 >logging list connections message 302013-302304 >logging list NewConnection message 302303 >logging list NewConnection message 302015 >logging list NewConnection message 302013 >logging list NewConnection message 303002 >logging list Dropped message 106001-106103 >logging list ConfigChange message 111008 >logging list ConfigChange message 111001 >logging list ConfigChange message 111010 >logging buffer-size 1048576 >logging monitor debugging >logging buffered warnings >! >access-group vlan4_access_in in interface vlan004_confidential1 >access-group vlan65_access_in in interface vlan065_confidential2 >access-group vlan66_access_in in interface vlan066_confidential3 >access-group vlan80_access_in in interface vlan080_confidential4 >! >service-policy global_policy global >service-policy test interface interconnection >service-policy imec_intranet_traffic-policy interface vlan065_confidential5 >service-policy imec_intranet_traffic-policy interface vlan066_confidential6 >service-policy imec_intranet_traffic-policy interface vlan080_confidential7 >service-policy imec_intranet_traffic-policy interface vlan082_confidential8 >service-policy imec_intranet_traffic-policy interface vlan083_confidential9 >! >: end
My second file is a list (list.txt). And the content and layout is something like this (in notepad++):
>username full name employid group left comp on >---------------------------------------------------------------------------------- >test16 confidential1 00014241 zzzz1 19-08-2017 >test38 confidential2 00014223 zzzz2 12-08-2017 >test47 confidential3 00013986 zzzz3 06-07-2017 >test85 confidential4 00013923 zzzz4 16-07-2017
Is it possible to run a script that takes every word in the "username" and "full name" column in the list.txt file and check if there is a match in the config.txt file? It would be great to have the output of the script in a third file that mentions what word (here username or full name) is found in the config.txt file and where.
Let's say I want to know if test38 is somewhere in the config.txt file? I now I can simply grep, but my list.txt file has around 100 users. I don't want to grep 100 times. On top of that, I'll get more lists in the future.