How to prevent grep from printing a trailing newline?

前端 未结 3 1003
失恋的感觉
失恋的感觉 2021-02-02 08:44

I am using grep to produce output that will be parsed by another program.

However, that program expects output only to be numeric or zero-bytes.

No

3条回答
  •  春和景丽
    2021-02-02 09:27

    Use tr -d to delete characters in a string:

    $ grep -c ' ' /etc/passwd | tr -d '\n'
    69$ grep -c ' ' /etc/passwd | tr -d '\n' | xxd 
    0000000: 3639                                     69
    $ 
    

提交回复
热议问题