Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have tab-demlimted file, I want to sort them only for red_ball as follows

input.txt

id      tagid    name
HH556   EN76     red_ball
JH678   EN45     green_ball
MH678   CV67     red_ball
TY896   RT56     red_ball

output.txt

Red_ball

id  tagid
HH556   EN76
MH678   CV67
TY896   RT56
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
{
  printf 'Red_ball\nid\ttagid\n\n'
  awk -F'\t'  'NR>1 && $3 == "red_ball" {print $1 "\t" $2}' < input.txt |
    sort
} > output.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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