newline

How to prevent grep from printing a trailing newline?

六眼飞鱼酱① 提交于 2020-08-21 04:22:01
问题 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. Now grep outputs a newline character after its output. I've checked the -Z option but it doesn't seem to work as I'm using grep for counting ( -c ). I am executing in sh , not bash . So nesting it into echo -n "$(grep -c pattern)" doesn't work either. How can I get rid off the trailing newline? 回答1: You can pipe it through tr and translate the \n to

How to prevent grep from printing a trailing newline?

▼魔方 西西 提交于 2020-08-21 04:21:53
问题 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. Now grep outputs a newline character after its output. I've checked the -Z option but it doesn't seem to work as I'm using grep for counting ( -c ). I am executing in sh , not bash . So nesting it into echo -n "$(grep -c pattern)" doesn't work either. How can I get rid off the trailing newline? 回答1: You can pipe it through tr and translate the \n to

How to prevent grep from printing a trailing newline?

拈花ヽ惹草 提交于 2020-08-21 04:21:09
问题 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. Now grep outputs a newline character after its output. I've checked the -Z option but it doesn't seem to work as I'm using grep for counting ( -c ). I am executing in sh , not bash . So nesting it into echo -n "$(grep -c pattern)" doesn't work either. How can I get rid off the trailing newline? 回答1: You can pipe it through tr and translate the \n to

How to tell git to preserve CRLF specifically for a single set of files? Mark a text file as binary?

送分小仙女□ 提交于 2020-08-10 19:45:13
问题 I want to set some of the text files in a repo to be cloned/downloaded as binary. Ie: Bypass the CRLF settings in git and just clone byte per byte. Context There are myriads of posts about CRLF in git. But normally they are about the general settings of whole projects, mainly depending on if you use Linux or Windows. But I face a situation that never found before. I am willing to set a folder in my project with sample emails as defined by the RFC 5322 which define that the end-of-line of the

How to tell git to preserve CRLF specifically for a single set of files? Mark a text file as binary?

こ雲淡風輕ζ 提交于 2020-08-10 19:45:12
问题 I want to set some of the text files in a repo to be cloned/downloaded as binary. Ie: Bypass the CRLF settings in git and just clone byte per byte. Context There are myriads of posts about CRLF in git. But normally they are about the general settings of whole projects, mainly depending on if you use Linux or Windows. But I face a situation that never found before. I am willing to set a folder in my project with sample emails as defined by the RFC 5322 which define that the end-of-line of the

HTML specification for rendering new lines?

喜夏-厌秋 提交于 2020-08-02 06:36:13
问题 I'm trying to render some simple HTML documents (contain mostly div and br tags) to plain text, but I'm struggling on when to add new lines. I assumed it would be quite simple with <div> and <br/> generating new lines, but it looks like there's various subtle rules. For example: <div>one line</div> <div>two lines</div> <hr/> <div>one line</div> <div></div> <div>still two lines because the empty div doesn't count</div> <hr/> <div>one line<br/></div> <div></div> <div>still two lines because the

HTML specification for rendering new lines?

孤人 提交于 2020-08-02 06:34:50
问题 I'm trying to render some simple HTML documents (contain mostly div and br tags) to plain text, but I'm struggling on when to add new lines. I assumed it would be quite simple with <div> and <br/> generating new lines, but it looks like there's various subtle rules. For example: <div>one line</div> <div>two lines</div> <hr/> <div>one line</div> <div></div> <div>still two lines because the empty div doesn't count</div> <hr/> <div>one line<br/></div> <div></div> <div>still two lines because the

Is there a way to stop input() from escaping \n?

守給你的承諾、 提交于 2020-07-16 10:41:11
问题 So I'm trying to allow my user to input \n in a string, to designate a new line. However for some reason that is translated into '\\n'. So I can do: inp = input().replace("\\n", "\n") but that seems a little cumbersome; is there a better way? 回答1: What you're looking for here is actually almost the opposite of what you're asking for. input does not escape the string in any way; it returns exactly the string the user typed. And, in fact, your attempted fix for that is, while probably not the