What does the following command do? grep -vn "abc" x

2015

What does the following command do?

grep -vn "abc" x

  1. A.

    It will print all of the lines in the file x that match the search string "abc"

  2. B.

    It will print all of the lines in file x that do not match the search string "abc"

  3. C.

    It will print the total number of lines in the file x that match the search string "abc"

  4. D.

    It will print the specific line numbers of the file x in which there is a match for string "abc"

Attempted by 40 students.

Show answer & explanation

Correct answer: B

Answer: The command prints all lines in file x that do NOT contain the string "abc", and each printed line is prefixed with its line number.

  • -v : invert match — select lines that do not match the pattern.

  • -n : show line numbers before each output line.

  • Combined effect: grep -vn "abc" x outputs every line that does not contain "abc", with each output line prefixed by its line number.

Example: If file x has three lines where line 1 is "apple", line 2 is "abc", and line 3 is "banana", then grep -vn "abc" x will print:

1:apple

3:banana

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…