1

I have a csv file

file.csv

C75ADANXX,5,20,,AGGCAGAA,AGAGTAGA,,,,,AB
C75ADANXX,5,21,,AGGCAGAA,GTAAGGAG,,,,,AB
C75ADANXX,5,22,,AGGCAGAA,ACTGCATA,,,,,AB
C75ADANXX,5,23,,AGGCAGAA,AAGGAGTA,,,,,TC
C75ADANXX,5,24,,AGGCAGAA,CTAAGCCT,,,,,TC
C75ADANXX,5,25,,TCCTGAGC,GCGTAAGA,,,,,TC

when I run the following awk command :

awk -F "," '{print$11}' file.csv  ##prints last cloumn

i want to extract lines with TC ; but the following command prints nothing

awk -F "," '{if($11==TC){print$0}}' file.csv

Where am I going wrong in writing the command ? Thank you.

2
  • can't reproduce, please specify your platform. Commented Aug 27, 2015 at 11:38
  • 2
    try awk -F, '$11~/TC/' Commented Aug 27, 2015 at 12:12

3 Answers 3

1

modified the command to

awk -F "," '{if($11=="TC\r"){print$0}}' file.csv 

this file was copied from windows , it had a carriage return character at the end of the line which was obviously not seen when you print only last column.

Sign up to request clarification or add additional context in comments.

Comments

0

Modify

awk -F "," '{if($11==TC){print$0}}' file.csv

To

awk -F "," '{if($11=="TC"){print$0}}' file.csv

OR even simple

awk -F, '$11=="TC"' file.csv
  • if($11==TC) Since variable TC is not defined before (because no quotes used, awk treats TC as variable not as string), it evaluates false always, so it prints nothing.

1 Comment

Still doesn't work Akshay, I tried both the solutions provided by you. Does it work at your end ?
0

try this one

grep ",TC$" file.csv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.