Skip to content
Advertisement

using only ‘grep’ command to get specific column

This below shows this some lines of csv file, i want to get the results that only get the Population column with only using grep command.

JavaScript

results i want:

JavaScript

The command i made for this problem was

JavaScript

which got results below

JavaScript

how can i get rid of the rest of things without using awk sed or any other things?

Advertisement

Answer

You may use a GNU grep with a PCRE pattern:

JavaScript

Here,

  • ^ – start of string
  • ([^,]*,){2} – two occurrences of any zero or more chars other than , and then a ,
  • K – match reset operator discarding all text matched so far
  • [^,]* – zero or more chars other than a comma.
Advertisement