0

i ve been reading lots of example here and i didn t find a solution to my problem. i have been given a list of 1200 IP one per line, and i need to verify if we have a trace of any of these ip in a log fine. so i have file ip.txt and log.txt, witch contain also one ip per line.

thxx for your help

nocomp
  • 1
  • 1
    grep -Fx -f ip.txt log.txt – Jetchisel Apr 03 '20 at 06:25
  • you should make that an answer. – pLumo Apr 03 '20 at 06:45
  • thxx a lot Jetchisel, but that doesn t work i ve added one of the ip from ip.txt in log.txt to see if it s find it, and it doesn t

    grep -Fx -f ip.txt log.txt

    nocomp@P0wnBox:/media/nocomp/2CFD-E610/ip$ any idea why? thx for your time

    – nocomp Apr 03 '20 at 07:26
  • You said you have two files, ip.txt and log.txt now if you have more to parse/do please update your question and post it. Show some sample input of both files and the desired output, and please post something what have you tried to do. – Jetchisel Apr 03 '20 at 07:29
  • yes i have two file, i ve added one ip frim ip.txt in log.txt in order to see if the script find it, but it doesn t when i run grep -Fx -f ip.txt log.txt – nocomp Apr 03 '20 at 07:31
  • Try replacing the x with w option from grep and see if it helps. – Jetchisel Apr 03 '20 at 07:54
  • There are almost certainly more elegant solutions (and you may need to adjust it to your data) but something along these lines may work: IFS=$'\n'; for i in $(cat ip.txt); do cat log.txt | grep -q $i && echo $i; done – moo Apr 03 '20 at 07:55
  • nop, same results :/ – nocomp Apr 03 '20 at 07:55
  • hi mark, it didn t worked either:nocomp@P0wnBox:/media/nocomp/2CFD-E610/ip$ IFS=$'\n'; for i in cat anssi.txt; do cat palo.txt | grep -q $i && echo $i; done nocomp@P0wnBox:/media/nocomp/2CFD-E610/ip$ – nocomp Apr 03 '20 at 07:56
  • @nocomp - i've adjusted my comment as the backticks (old style command substition) were not displayed correctly (https://unix.stackexchange.com/questions/27428/what-does-backquote-backtick-mean-in-commands). Try the edited post – moo Apr 03 '20 at 08:00
  • @nocomp, then you need to post both sample of the files in question. – Jetchisel Apr 03 '20 at 08:01
  • In case the demand gets more complex: checking if an IP is inside a list of networks (ranges of IPs), there's a dedicated tool: grepcidr – A.B Apr 04 '20 at 08:43

1 Answers1

0

I got it working by doing

comm -12 <(sort ip.txt) <(sort log.txt)
Kusalananda
  • 333,661
nocomp
  • 1