I want to search "C" in the grades column inside the file "input.csv":

001,A B,78,23,C 
003,F YZ,100,1,*

and what I'm trying is:

cut -d"," -f4 input.csv | grep "C"
  • What is the expected output?
    – pfnuesel
    Jan 24 '16 at 16:51
  • Looks to me like column 5 has the C, not column 4
    – Jeff Schaller
    Jan 24 '16 at 17:02

Here grade is in 5th column of file, so following awk will give you expected results:

awk -F, 'toupper($5)=="C"' input.csv
grep ,C$ <in >out

...is too short to be accepted without this bit.

  • Quoting the regex might be handy if any shells get frisky with any metacharacters present in the unquoted regex.
    – thrig
    Jan 24 '16 at 17:06
  • 1
    @thirig - there are no characters which might cause them to be frisky here.
    – mikeserv
    Jan 24 '16 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.