Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • output should not inc;ude the " or , ( only hostnames and IP's Commented Jan 9, 2018 at 14:18
  • question why if I redirect the output to file - the I get shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory Commented Jan 9, 2018 at 14:33
  • example cat file | awk '/ip/ && NR-1==h_num && NR-2==n{ r=h" "$3; gsub(/[,"]+/, "", r); print r } /"host_name"/{ h_num=NR; h=$3 } /"name"/{ n=NR }' > new_file Commented Jan 9, 2018 at 14:34
  • @jango, this example cat file | awk ... is bad practice. Don't take that habit. Use awk '/ip/ && NR-1==h_num && NR-2==n{ r=h" "$3; gsub(/[,"]+/, "", r); print r } /"host_name"/{ h_num=NR; h=$3 } /"name"/{ n=NR }' yourfile > new_file. Besides, file is abstracted, you should specify your own actual file name Commented Jan 9, 2018 at 14:35