nerdexam
CompTIA

XK0-004 · Question #207

An administrator has a CSV file named hosts.csv. The contents of hosts.csv include the following: 192.168.2.57,lnx1prd.example.com,Linux,Production 192.168.2.58,lnx2prd.example.com,Linux,Production 19

The correct answer is A. for ip in $(grep "Linux" hosts.csv | cut -d"," -f1); do echo -n "$ip,";. Read the command syntax, cut is used to cut parts of lines from specified files or piped data and print the result to standard output. Sed is used for insertion, deletion, search and replace(substitution). We meed to use the standard output from the first part of the command to f

Scripting, Containers and Automation

Question

An administrator has a CSV file named hosts.csv. The contents of hosts.csv include the following:

192.168.2.57,lnx1prd.example.com,Linux,Production 192.168.2.58,lnx2prd.example.com,Linux,Production 192.168.1.4,server15.example.com,Windows,Development The administrator needs to create a second comma-separated list of only the Linux server IP addresses. Which of the following commands would achieve this need?

Options

  • Afor ip in $(grep "Linux" hosts.csv | cut -d"," -f1); do echo -n "$ip,";
  • Bfor ip in $( cut -d"," -f1 hosts.csv | grep "Linux"); do echo -n "$ip,";

How the community answered

(23 responses)
  • A
    78% (18)
  • B
    22% (5)

Explanation

Read the command syntax, cut is used to cut parts of lines from specified files or piped data and print the result to standard output. Sed is used for insertion, deletion, search and replace(substitution). We meed to use the standard output from the first part of the command to feed the second part.

Topics

#bash scripting#grep#cut#CSV processing

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice