Remove empty lines in a text file via grep

后端 未结 11 1677
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 23:17

FILE:

hello

world

foo

bar

How can I remove all the empty new lines in this FILE?

Output of command:

11条回答
  •  余生分开走
    2020-12-12 23:52

    If you want to know what the total lines of code is in your Xcode project and you are not interested in listing the count for each swift file then this will give you the answer. It removes lines with no code at all and removes lines that are prefixed with the comment //

    Run it at the root level of your Xcode project.

    find . \( -iname \*.swift \) -exec grep -v '^[[:space:]]*$' \+ | grep -v -e '//' | wc -l
    

    If you have comment blocks in your code beginning with /* and ending with */ such as:

    /*
     This is an comment block 
    */
    

    then these will get included in the count. (Too hard).

提交回复
热议问题