#!/bin/bash
for ip in $(seq 1 255 );do
host 10.11.1.$ip >> nameserver2.txt
done
I'm trying to clean up a file I created with this little batch script.
I have more results with names of servers found and not found.
Host 1.1.11.10.in-addr.arpa. not found: 3 (NXDOMAIN)
Host 2.1.11.10.in-addr.arpa. not found: 3 (NXDOMAIN)
I'm doing a nameserver2.txt grep | grep name which displays only existing servers. Except that I have too much information on each line
5.1.11.10.in-addr.arpa domain name pointer serv1.domain.com
6.1.11.10.in-addr.arpa domain name pointer serv2.domain.com
I would like to have only the 1st character each line (so the last of each IP and the name of the server
I'm making a
cat nameserver2.txt | grep name | cut -d. -f1
but in this case I only have information on two so in the end I made this order:
Thank you for being so quick and fair in your answers
The 1st proposition works perfectly. the second almost except that for the servers not found, there is this:
;; reached
( you can send me a other command line if you want )
in any case to you two
just for knowledge, could it have been done with cat grep and cut?
There's NO string like "reached" in your samples, nor semicolons. Those don't show up in my host calls, either. Replace ! /^Host/ with /domain/ or /name/ or /pointer/ . If that doesn't help, show your input data.
cat is by no means needed in any of your attempts as both grep and cut can open files by themselves, or you can redirect stdin for them. grep ping the first number is quite easy, like
$ host 82.165.230.17 | grep -o "^[^.]*"
17
, but extracting the remote hostname not so as you don't know what the FQDN looks like. The nearest I get is
Yes you are right. it's my fault. There somes lines that i didn't see in the original file, like ";; connection timed out; no servers could be reached"