awk - Extracting content of a file in bash -
i have file content like: (this nmap output)
nmap scan report x.x.x.x host (0.12s latency). port state service 23/tcp open telnet | telnet-brute: | accounts | var1:var2 | statistics | performed 5 guesses in 3 seconds, average tps: 1 | |_ error: many retries, aborted ... nmap scan report y.y.y.y host (0.17s latency). port state service 23/tcp open telnet | telnet-brute: | accounts | var3:var4 | statistics |_ performed 2 guesses in 13 seconds, average tps: 0 nmap scan report z.z.z.z host (0.19s latency). port state service 23/tcp open telnet | telnet-brute: | accounts | no valid accounts found
i want extract pattern:
x.x.x.x var1:var2 y.y.y.y var3:var4
what tried is:
#!/bin/bash nmapresult=$1 rm oooo while read line if [[ "$line" == *nmap* ]]; out=$(grep "nmap" -a6) if [[ "$out" == *valid* ]]; continue else grep "nmap" -a6 >> oooo echo fi fi done < $nmapresult
but not true , not want.
could possibly me on thread?
thanks
$ awk -v rs= -f'\n' '{n=split($1,a,/ /); sub(/\| */,"",$7); print a[n], $7}' file x.x.x.x var1:var2 y.y.y.y var3:var4 z.z.z.z no valid accounts found
or if want exclude 3rd line of output, might want:
$ awk -v rs= -f'\n' '$7~/:/{n=split($1,a,/ /); sub(/\| */,"",$7); print a[n], $7}' file x.x.x.x var1:var2 y.y.y.y var3:var4
Comments
Post a Comment