So! I have an nmap scan that saves the output to a file, nmapscan.txt:
sudo nmap -sP 192.168.1* > nmapscan.txt I also have a few other commands to clean up and save all desired output to one file, livehosts.txt:
cat ./temp/nmapscan.txt | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' > ./temp/macaddresses.txt Which saves the mac addresses. And:
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' ./temp/nmapscan.txt > ./temp/ipaddresses.txt Which saves the IP addresses. And:
cat ./temp/nmapscan.txt | grep -o -P '(?<=for).*(?=.attlocal)' > ./temp/hostnames1.txt Which saves the hostnames. And:
cut -d' ' -f 2 ./temp/hostnames1.txt > ./temp/hostnames2.txt Which I did to clean up the hostnames (sorry, forgot to include this in original post)... And:
cut -d' ' -f 1 ./temp/hostnames2.txt | paste ./temp/macaddresses.txt ./temp/ipaddresses.txt - > ./temp/livehosts.txt .. which is the end product that combines the desired data and displays like:
xx:xx:xx:xx:xx:xx 192.168.1.1 Netgear xx:xx:xx:xx:xx:xx 192.168.1.111 John's Toilet Cam I want to do the scan and write, again, and want the livehosts.txt file to be more or less, updated. Simply doing the scan and write again, as is, writes over the file. And not all devices are connected at different times.
I've tried:
>> But that just doubles up the data already in the file.
Would doubling up the data, cutting recurring data, then writing to a new file be the best way to go about it?
How would you go about doing this? Thanks!
nmapscan.txtthe same file as./temp/nmapscan.txt- or are you perhaps re-processing the same file over again?sort -u.