Fixing presentation with AWKWhat are the differences between Perl, Python, AWK and sed?How to do a recursive find/replace of a string with awk or sed?What is the difference between sed and awk?How to use “:” as awk field separator?AWK: Access captured group from line patternUsing awk to print all columns from the nth to the lastAWK multiple delimiterawk parsing with fixed number of fieldsRemove a fixed prefix/suffix from a string in BashHow do I use shell variables in an awk script?

Is this apparent Class Action settlement a spam message?

Balance Issues for a Custom Sorcerer Variant

Why not increase contact surface when reentering the atmosphere?

Is exact Kanji stroke length important?

How to write papers efficiently when English isn't my first language?

Method to test if a number is a perfect power?

Proof of work - lottery approach

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

How does buying out courses with grant money work?

Increase performance creating Mandelbrot set in python

What is the best translation for "slot" in the context of multiplayer video games?

Applicability of Single Responsibility Principle

Integer addition + constant, is it a group?

How do I go from 300 unfinished/half written blog posts, to published posts?

CREATE opcode: what does it really do?

Why Were Madagascar and New Zealand Discovered So Late?

How easy is it to start Magic from scratch?

Why are there no referendums in the US?

What is the intuitive meaning of having a linear relationship between the logs of two variables?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Class Action - which options I have?

Two monoidal structures and copowering

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?



Fixing presentation with AWK


What are the differences between Perl, Python, AWK and sed?How to do a recursive find/replace of a string with awk or sed?What is the difference between sed and awk?How to use “:” as awk field separator?AWK: Access captured group from line patternUsing awk to print all columns from the nth to the lastAWK multiple delimiterawk parsing with fixed number of fieldsRemove a fixed prefix/suffix from a string in BashHow do I use shell variables in an awk script?













-1















I'm creating a little script that reads the contents of a file containing a list of domains. The domains are then piped through dig +short to extract their IP addresses, I then pipe each of the IP's through geoiplookup to get their county of origin, and use AWK to present them in the following format:



IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country

for domain in $(cat "$1"); do dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain | awk 'NR==1print ","$5,$6,$7,$8' >> Blacklist.csv ; done


Right now, I'm having an issue with the first IP Address displaying at the bottom, like so:



 , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address


Any ideas on how my presentation can be tidied up?



=======================================================================



EDIT:



Running Script



Output CSV - As you can see, The IP Address in Cell A1 has been incorrectly placed in Cell A5



EDIT 2: Samples
Input File - Text File Containing List of Domains:



helloworld.com
rubyonrails.org
sublimetext.com
gnu.org


DIG Output:



ryan@ubuntu:~/Desktop$ for domain in $(cat stackdemo.txt); do dig +short $domain ; done
69.25.240.212
185.199.108.153
45.55.41.223
209.51.188.148


Final Combined Output:



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States
209.51.188.148


=======================================================================



NON DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States


209.51.188.148



DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
209.51.188.148 ,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States









share|improve this question
























  • If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

    – RavinderSingh13
    Mar 7 at 12:56






  • 2





    I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

    – Socowi
    Mar 7 at 12:59







  • 1





    Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

    – RavinderSingh13
    Mar 7 at 13:15











  • @RavinderSingh13 Samples posted

    – NigerianWizard
    Mar 7 at 13:36











  • @NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

    – RavinderSingh13
    Mar 7 at 13:47
















-1















I'm creating a little script that reads the contents of a file containing a list of domains. The domains are then piped through dig +short to extract their IP addresses, I then pipe each of the IP's through geoiplookup to get their county of origin, and use AWK to present them in the following format:



IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country

for domain in $(cat "$1"); do dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain | awk 'NR==1print ","$5,$6,$7,$8' >> Blacklist.csv ; done


Right now, I'm having an issue with the first IP Address displaying at the bottom, like so:



 , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address


Any ideas on how my presentation can be tidied up?



=======================================================================



EDIT:



Running Script



Output CSV - As you can see, The IP Address in Cell A1 has been incorrectly placed in Cell A5



EDIT 2: Samples
Input File - Text File Containing List of Domains:



helloworld.com
rubyonrails.org
sublimetext.com
gnu.org


DIG Output:



ryan@ubuntu:~/Desktop$ for domain in $(cat stackdemo.txt); do dig +short $domain ; done
69.25.240.212
185.199.108.153
45.55.41.223
209.51.188.148


Final Combined Output:



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States
209.51.188.148


=======================================================================



NON DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States


209.51.188.148



DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
209.51.188.148 ,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States









share|improve this question
























  • If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

    – RavinderSingh13
    Mar 7 at 12:56






  • 2





    I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

    – Socowi
    Mar 7 at 12:59







  • 1





    Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

    – RavinderSingh13
    Mar 7 at 13:15











  • @RavinderSingh13 Samples posted

    – NigerianWizard
    Mar 7 at 13:36











  • @NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

    – RavinderSingh13
    Mar 7 at 13:47














-1












-1








-1








I'm creating a little script that reads the contents of a file containing a list of domains. The domains are then piped through dig +short to extract their IP addresses, I then pipe each of the IP's through geoiplookup to get their county of origin, and use AWK to present them in the following format:



IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country

for domain in $(cat "$1"); do dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain | awk 'NR==1print ","$5,$6,$7,$8' >> Blacklist.csv ; done


Right now, I'm having an issue with the first IP Address displaying at the bottom, like so:



 , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address


Any ideas on how my presentation can be tidied up?



=======================================================================



EDIT:



Running Script



Output CSV - As you can see, The IP Address in Cell A1 has been incorrectly placed in Cell A5



EDIT 2: Samples
Input File - Text File Containing List of Domains:



helloworld.com
rubyonrails.org
sublimetext.com
gnu.org


DIG Output:



ryan@ubuntu:~/Desktop$ for domain in $(cat stackdemo.txt); do dig +short $domain ; done
69.25.240.212
185.199.108.153
45.55.41.223
209.51.188.148


Final Combined Output:



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States
209.51.188.148


=======================================================================



NON DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States


209.51.188.148



DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
209.51.188.148 ,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States









share|improve this question
















I'm creating a little script that reads the contents of a file containing a list of domains. The domains are then piped through dig +short to extract their IP addresses, I then pipe each of the IP's through geoiplookup to get their county of origin, and use AWK to present them in the following format:



IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country

for domain in $(cat "$1"); do dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain | awk 'NR==1print ","$5,$6,$7,$8' >> Blacklist.csv ; done


Right now, I'm having an issue with the first IP Address displaying at the bottom, like so:



 , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address , Country
IP Address


Any ideas on how my presentation can be tidied up?



=======================================================================



EDIT:



Running Script



Output CSV - As you can see, The IP Address in Cell A1 has been incorrectly placed in Cell A5



EDIT 2: Samples
Input File - Text File Containing List of Domains:



helloworld.com
rubyonrails.org
sublimetext.com
gnu.org


DIG Output:



ryan@ubuntu:~/Desktop$ for domain in $(cat stackdemo.txt); do dig +short $domain ; done
69.25.240.212
185.199.108.153
45.55.41.223
209.51.188.148


Final Combined Output:



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States
209.51.188.148


=======================================================================



NON DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States


209.51.188.148



DESIRED OUTPUT



ryan@ubuntu:~/Desktop/Demo$ cat Blacklist.csv 
209.51.188.148 ,United States
69.25.240.212 ,Netherlands
185.199.108.153 ,United States
45.55.41.223 ,United States






bash awk geoip






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 13:50







NigerianWizard

















asked Mar 7 at 12:53









NigerianWizardNigerianWizard

61




61












  • If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

    – RavinderSingh13
    Mar 7 at 12:56






  • 2





    I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

    – Socowi
    Mar 7 at 12:59







  • 1





    Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

    – RavinderSingh13
    Mar 7 at 13:15











  • @RavinderSingh13 Samples posted

    – NigerianWizard
    Mar 7 at 13:36











  • @NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

    – RavinderSingh13
    Mar 7 at 13:47


















  • If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

    – RavinderSingh13
    Mar 7 at 12:56






  • 2





    I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

    – Socowi
    Mar 7 at 12:59







  • 1





    Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

    – RavinderSingh13
    Mar 7 at 13:15











  • @RavinderSingh13 Samples posted

    – NigerianWizard
    Mar 7 at 13:36











  • @NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

    – RavinderSingh13
    Mar 7 at 13:47

















If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

– RavinderSingh13
Mar 7 at 12:56





If I get it correctly you want to run dig command for all ips in your Input_file. If this is the case then could you please mention dummy sample of input_file(with ips) and dummy sample of dig output in your post(for 1 IP and with final total output) and let us know then?

– RavinderSingh13
Mar 7 at 12:56




2




2





I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

– Socowi
Mar 7 at 12:59






I don't understand ... | tr ... >> Blacklist.csv | geoiplookup. Is the combination of >> and | really what you want?

– Socowi
Mar 7 at 12:59





1




1





Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

– RavinderSingh13
Mar 7 at 13:15





Kindly post your samples(as text) in your post, do not post them in form of images or links please @NigerianWizard

– RavinderSingh13
Mar 7 at 13:15













@RavinderSingh13 Samples posted

– NigerianWizard
Mar 7 at 13:36





@RavinderSingh13 Samples posted

– NigerianWizard
Mar 7 at 13:36













@NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

– RavinderSingh13
Mar 7 at 13:47






@NigerianWizard, ok let me re-phrase it. You are having list of domains which you are passing or want to pass to dig to get their ips. ONce you get those you are passing them to geoiplookup; Where you are facing issues in re-arrnaging its output, Am I right? If yes then you can simply tell us NON desired output then Desired output since it is still not clear in your post. Because in your expected output somewhere ip or somewhere country is missing so not clear, please provide more details.

– RavinderSingh13
Mar 7 at 13:47













1 Answer
1






active

oldest

votes


















0














Still not fully clear to me, assuming that your dig command and your geoiplookup commands will NOT give empty output, if this is the case try.



while read line
do
dig "$line" > "dig_output"
geoiplookup "$line" > "lookup_output"
done < "domain_file"


Now combine output by doing:



paste -d"," "dig_output" "lookup_output"


Fair warning: I haven't tested it since lack of softwares.






share|improve this answer























  • @NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

    – RavinderSingh13
    Mar 14 at 5:48











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044278%2ffixing-presentation-with-awk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Still not fully clear to me, assuming that your dig command and your geoiplookup commands will NOT give empty output, if this is the case try.



while read line
do
dig "$line" > "dig_output"
geoiplookup "$line" > "lookup_output"
done < "domain_file"


Now combine output by doing:



paste -d"," "dig_output" "lookup_output"


Fair warning: I haven't tested it since lack of softwares.






share|improve this answer























  • @NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

    – RavinderSingh13
    Mar 14 at 5:48
















0














Still not fully clear to me, assuming that your dig command and your geoiplookup commands will NOT give empty output, if this is the case try.



while read line
do
dig "$line" > "dig_output"
geoiplookup "$line" > "lookup_output"
done < "domain_file"


Now combine output by doing:



paste -d"," "dig_output" "lookup_output"


Fair warning: I haven't tested it since lack of softwares.






share|improve this answer























  • @NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

    – RavinderSingh13
    Mar 14 at 5:48














0












0








0







Still not fully clear to me, assuming that your dig command and your geoiplookup commands will NOT give empty output, if this is the case try.



while read line
do
dig "$line" > "dig_output"
geoiplookup "$line" > "lookup_output"
done < "domain_file"


Now combine output by doing:



paste -d"," "dig_output" "lookup_output"


Fair warning: I haven't tested it since lack of softwares.






share|improve this answer













Still not fully clear to me, assuming that your dig command and your geoiplookup commands will NOT give empty output, if this is the case try.



while read line
do
dig "$line" > "dig_output"
geoiplookup "$line" > "lookup_output"
done < "domain_file"


Now combine output by doing:



paste -d"," "dig_output" "lookup_output"


Fair warning: I haven't tested it since lack of softwares.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 13:56









RavinderSingh13RavinderSingh13

30.3k41639




30.3k41639












  • @NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

    – RavinderSingh13
    Mar 14 at 5:48


















  • @NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

    – RavinderSingh13
    Mar 14 at 5:48

















@NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

– RavinderSingh13
Mar 14 at 5:48






@NigerianWizard, could you please try above once and let me know? In case this is not working then paste output of dig +short $domain | tr 'n' ' ' >> Blacklist.csv | geoiplookup $domain once too?

– RavinderSingh13
Mar 14 at 5:48




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044278%2ffixing-presentation-with-awk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко