I have a files FB_Dataset.csv simply contains 21 columns, whereas FB_Dataset.csv is a comma delimited file. The general scheme of FB_Dataset.csv is posted below.

enter image description here

I need to extract the word 'Trump' (Ignore case) mentioned in the file and number of likes (10th column) greater than 100. And finally generate a new file with post_id (2nd column) and sorted like_count (10th column) and name it “trump.txt”.

I'm new to unix and learned that to extract the 2 conditions separately. The code would probably be grep -i -o 'Trump' FB_Dataset.csv for first condition and awk '$10 > 100{print}' FB_Dataset.csv for the second condition. What should i do next?

Thank you

  • Please don't post images of text. Copy and paste the text itself into your question and format it as code by selecting it and pressing Ctrl-K or by using the editor's {} icon. This appears to be a CSV file, so copy-paste some or all of the text file rather than a screenshot of the file loaded into a spreadsheet.
    – cas
    Oct 24, 2019 at 8:47

1 Answer 1


If I understood correctly you need

awk -F, '/[tT]rump/ && $3>100' FB_Dataset.csv | sort -t, -k 3,3n > trump.txt

Searching for "trump" and numbers greater than 100 is done by awk, final sorting is performed by sort numerically on the third column (-k 3,3n). The switches -F, and -t, are needed to use comma as a delimiter.

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.