linux - search in output and cat from specific line to specific line and search again -


i wrote like:

out=$( nmap -p "$port" --script=http-headers.nse "$ip" 

for example output is:

|http-headers:  |   server: apache |   vary: accept-encoding |   content-type: text/html; charset=utf-8 |   date: thu, 06 feb 2014 07:31:33 gmt |   age: 25 |   connection: close 

but length of output changeable. want search between lines in output (better use sed or awk) , check condition. example if sees apache line 3 till line 8 echo right

edit:

my script:

#!/bin/bash  echo "reading data - headers - both"  if [ $# -ne 3 ];     echo "usage: ./nmap <port-range> <ip-list> <d || h || b>"     exit 1 fi  if [ $3 == h ];     while read -r -u3 port;     while read -r -u4 ip;           echo -n "$ip $port: "         out=$( nmap -p "$port" --script=http-headers.nse "$ip" |         tail -n 13 |          awk -f: '{print $2; exit}')   in other lines         [[ $out == *apache* ]] && echo right || echo wrong      done 4< "$2"     done 3< "$1"  elif [ $3 == d ];     echo data elif [ $3 == b ];      echo both fi 

i want put right result in file...for example:

cat right.txt ip1  port1 ip2  port2  cat wrong.txt ip1 port1 ip2 port2 

here fix

#!/bin/bash  echo "reading data - headers - both"  if [ $# -ne 3 ];     echo "usage: ./nmap <port-range> <ip-list> <d || h || b>"     exit 1 fi  headers () {     join -a1 -a2 -j 2 $2 $1 |while read ip port              echo -n "$ip $port:"         out=$(nmap -p "$port" --script=http-headers.nse "$ip" | tac | awk -f: 'nr<=13&&/apache/{print $2; exit}')            if [[ "$out" == *apache* ]];             echo $ip $port >> right.txt         else             echo $ip $port >> wrong.txt         fi      done }   case $3 in    "h") headers ;;   "d") echo data;;   "b") echo both;;   "*") echo "wrong input"        exit;; esac 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -