There is a broken line

whois ya.ru |for i in 6 13 14 15 16 17; do awk 'NR==$i{print $1 "\t\t" $2}'; done; //в выводе пусто 

The task is to output 6 13 14 15 16 17 lines from the whois output. If you replace $ i with 6, then everything works fine:

 whois ya.ru |for i in 6 13 14 15 16 17; do awk 'NR==6{print $1 "\t\t" $2}'; done; domain: YA.RU 

the question is actually how to transfer the values ​​from the loop to the NR, or how to do without the loop at all

  • I, and the background, will be grateful if anyone, in the commentary below, can move the loop for awk, so far nothing comes out of me - Enginer Rod
  • Solve it entirely on awk — it’s just for such tasks. - 0andriy

1 answer 1

 whois ya.ru | sed -n '6p;13,17p' 

-n tells sed not to print lines by default, after which we ask them to print ( p ) for the 6th line and for the range from 13 to 17. Although I would suggest focusing on the contents of the whois lines, and not on their order:

 whois ya.ru | grep -E 'domain:|paid-till:|created:|free-date:|source:' 

UPD

The awk option:

 whois ya.ru | awk 'NR==6 || NR==13,NR==17{print $1 "\t\t" $2}' 
  • Cool! Thank you! This is an easy and simple solution to the problem, but I would like to deal with the interaction of bash and awk for the future. What is the actual error in the transmission of the argument? - Enginer Rod
  • is it possible, with the help of sed, to weed out the text output going to the whois google.com output before the line domain: google.com? that is, a heavy array of textual information? - Enginer Rod
  • one
    @EnginerRod To get started, try for i in 6 13 14 15 16 17; do echo '$i'; done; for i in 6 13 14 15 16 17; do echo '$i'; done; see $i 6 times, because in parameters in single quotes variables are not interpolated. If you replace the quotes with double quotes, you will see the numbers. But awk doesn’t like something after that, I don’t understand it - Mike
  • @EnginerRod Well, for example, sed '/domain/p;1,/domain/d;' you have to print domain first, then delete from line 1 before it, because otherwise it will delete the same. Although that "weighty array of information" in the first position has a '%' sign, it is easier to grep delete lines beginning with this character - Mike
  • one
    @EnginerRod And by the way, the idea with awk in a loop is not working by definition. the cycle will run it 6 times. And when he first starts, he will read completely what has come to the standard input and the second start will have nothing on the input - Mike