Skip to main content
deleted 237 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

I need some help to display grep output in table columns.

I have a script that grab info from whois to display the creation, expiry date and ns server of specific domain names.

#!/bin/sh
cat domain-file.txt  | while read line ; do
lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
echo "$lLine\t" >> table.csv;
sleep 3
echo "\n$lLine"
host=whois.nic.re
created=$(whois -h $host $lLine | egrep -i 'created:')
echo "$created\t" >> table.csv
sleep 2
expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
echo "$expire\t" >> table.csv
sleep 2
nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
echo "$nserver\t" >> table.csv
echo "------------------------------------------" >> table.csv
done
exit

Everything is working well except that im trying to display the output in a table like this :

Domain          Created Date    Expiry date     NS
abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        

Instead im getting an output like that :

abcd.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.abcd.com 
nserver: ns2.abcd.com
------------------------------------------
1234.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.1234.com 
nserver: ns2.1234.com
------------------------------------------

I have tried many ways with sed and awk but i always get messy table. Im pretty new with shell script so If anyone can help with this it would be much appreciated.

Thank you

I need some help to display grep output in table columns.

I have a script that grab info from whois to display the creation, expiry date and ns server of specific domain names.

#!/bin/sh
cat domain-file.txt  | while read line ; do
lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
echo "$lLine\t" >> table.csv;
sleep 3
echo "\n$lLine"
host=whois.nic.re
created=$(whois -h $host $lLine | egrep -i 'created:')
echo "$created\t" >> table.csv
sleep 2
expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
echo "$expire\t" >> table.csv
sleep 2
nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
echo "$nserver\t" >> table.csv
echo "------------------------------------------" >> table.csv
done
exit

Everything is working well except that im trying to display the output in a table like this :

Domain          Created Date    Expiry date     NS
abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        

Instead im getting an output like that :

abcd.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.abcd.com 
nserver: ns2.abcd.com
------------------------------------------
1234.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.1234.com 
nserver: ns2.1234.com
------------------------------------------

I have tried many ways with sed and awk but i always get messy table. Im pretty new with shell script so If anyone can help with this it would be much appreciated.

Thank you

I need to display grep output in table columns.

I have a script that grab info from whois to display the creation, expiry date and ns server of specific domain names.

#!/bin/sh
cat domain-file.txt  | while read line ; do
lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
echo "$lLine\t" >> table.csv;
sleep 3
echo "\n$lLine"
host=whois.nic.re
created=$(whois -h $host $lLine | egrep -i 'created:')
echo "$created\t" >> table.csv
sleep 2
expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
echo "$expire\t" >> table.csv
sleep 2
nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
echo "$nserver\t" >> table.csv
echo "------------------------------------------" >> table.csv
done
exit

Everything is working well except that im trying to display the output in a table like this :

Domain          Created Date    Expiry date     NS
abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        

Instead im getting an output like that :

abcd.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.abcd.com 
nserver: ns2.abcd.com
------------------------------------------
1234.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.1234.com 
nserver: ns2.1234.com
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
deleted 119 characters in body
Source Link
muru
  • 78.1k
  • 16
  • 213
  • 319
            #!/bin/sh
            cat domain-file.txt  | while read line ; do
            lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
            echo "$lLine\t" >> table.csv;
            sleep 3
            echo "\n$lLine"
            host=whois.nic.re
            created=$(whois -h $host $lLine | egrep -i 'created:')
            echo "$created\t" >> table.csv
            sleep 2
            expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
            echo "$expire\t" >> table.csv
            sleep 2
            nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
            echo "$nserver\t" >> table.csv
            echo "------------------------------------------" >> table.csv
            done
            exit
            Domain          Created Date    Expiry date     NS
            abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
            1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        
            abcd.com        
            Created date: 19/01/2018        
            Expiry date: 19/01/2019         
            nserver: ns.abcd.com 
            nserver: ns2.abcd.com
            ------------------------------------------
            1234.com        
            Created date: 19/01/2018        
            Expiry date: 19/01/2019         
            nserver: ns.1234.com 
            nserver: ns2.1234.com
            ------------------------------------------

I have tried many ways with "sed"sed and "awk"awk but i always get messy table. Im pretty new with shell script so If anyone can help with this it would be much appreciated.

            #!/bin/sh
            cat domain-file.txt  | while read line ; do
            lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
            echo "$lLine\t" >> table.csv;
            sleep 3
            echo "\n$lLine"
            host=whois.nic.re
            created=$(whois -h $host $lLine | egrep -i 'created:')
            echo "$created\t" >> table.csv
            sleep 2
            expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
            echo "$expire\t" >> table.csv
            sleep 2
            nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
            echo "$nserver\t" >> table.csv
            echo "------------------------------------------" >> table.csv
            done
            exit
            Domain          Created Date    Expiry date     NS
            abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
            1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        
            abcd.com        
            Created date: 19/01/2018        
            Expiry date: 19/01/2019         
            nserver: ns.abcd.com 
            nserver: ns2.abcd.com
            ------------------------------------------
            1234.com        
            Created date: 19/01/2018        
            Expiry date: 19/01/2019         
            nserver: ns.1234.com 
            nserver: ns2.1234.com
            ------------------------------------------

I have tried many ways with "sed" and "awk" but i always get messy table. Im pretty new with shell script so If anyone can help with this it would be much appreciated.

#!/bin/sh
cat domain-file.txt  | while read line ; do
lLine="$(echo $line | tr '[A-Z]' '[a-z]')"
echo "$lLine\t" >> table.csv;
sleep 3
echo "\n$lLine"
host=whois.nic.re
created=$(whois -h $host $lLine | egrep -i 'created:')
echo "$created\t" >> table.csv
sleep 2
expire=$(whois -h $host $lLine | egrep -i 'Expiry Date:')
echo "$expire\t" >> table.csv
sleep 2
nserver=$(whois -h $host $lLine | egrep -i 'nserver:')
echo "$nserver\t" >> table.csv
echo "------------------------------------------" >> table.csv
done
exit
Domain          Created Date    Expiry date     NS
abcd.com        19/01/2018      19/01/2019      ns.abcd.com ns2.abcd.com
1234.com        19/01/2018      19/01/2019      ns.1234.com ns2.1234.com        
abcd.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.abcd.com 
nserver: ns2.abcd.com
------------------------------------------
1234.com        
Created date: 19/01/2018        
Expiry date: 19/01/2019         
nserver: ns.1234.com 
nserver: ns2.1234.com
------------------------------------------

I have tried many ways with sed and awk but i always get messy table. Im pretty new with shell script so If anyone can help with this it would be much appreciated.

Source Link
Marcus
  • 3
  • 1
  • 1
  • 3
Loading