1

I am trying to print out the Chinese font I have in my laptop, and sort the output with respect to their name that could be referred to in LaTeX. This could be done with the following command:

fc-list :lang=zh-cn | awk -F": " '{$1=""; print}' | sort

It finds the font list, then after first occurrence of : and a single space, which is where the names of the font show up. Then we of course sort it.

The problem here is though, there are fonts named like .PingFang SC, which is sorted to the very front and is not that consistent with the rest. Is there a way to sort disregarding the period?

It may not be a good choice to remove the period, which will change the actual name of the font and thus make the reference hard.

1 Answer 1

1

Try using sort -d (“dictionary order”, which seems to ignore non-alpha characters):

$ printf "Orange\n.PingFang\nRed\n" | sort
.PingFang
Orange
Red

$ printf "Orange\n.PingFang\nRed\n" | sort -d
Orange
.PingFang
Red
3
  • That works! Thanks so much! Do you have ideas on the blank output resulted by adding the extra space?
    – zyy
    Oct 22, 2018 at 1:18
  • I’m sorry, but I don’t understand what you’re saying.  Can you edit your question to show some examples of your input (i.e., the output of fc-list) and your output? Oct 22, 2018 at 1:38
  • I see what the problem is, the extra space is resulted from the command $1="". It is all good now, thanks!
    – zyy
    Oct 22, 2018 at 1:52

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.