text-manipulation

How to split file on first empty line in a portable way in shell (e.g. using sed)?

こ雲淡風輕ζ 提交于 2019-11-30 23:04:17
问题 I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first line containing only CR = ' \r ' character) using a shell script . How to do this in a portable way (for example using sed , but without GNU extensions)? One can assume that empty line would not be first line in a file. Empty line can got to either, none or both of files;

Insert multiple lines of text before specific line using Bash

五迷三道 提交于 2019-11-30 13:58:50
I am trying to insert a few lines of text before a specific line, but keep getting sed errors when I try to add a new line character. My command looks like: sed -r -i '/Line to insert after/ i Line one to insert \\ second new line to insert \\ third new line to insert' /etc/directory/somefile.txt The error that is reported is: sed: -e expression #1, char 77: unterminated `s' command I've tried, using \n , \\ (as in the example), no character at all, just moving the second line to the next line. I've also tried something like: sed -r -i -e '/Line to insert after/ i Line one to insert' -e

How to get Git log with short stat in one line?

ぃ、小莉子 提交于 2019-11-30 08:21:24
Following command outputs following lines of text on console git log --pretty=format:"%h;%ai;%s" --shortstat ed6e0ab;2014-01-07 16:32:39 +0530;Foo 3 files changed, 14 insertions(+), 13 deletions(-) cdfbb10;2014-01-07 14:59:48 +0530;Bar 1 file changed, 21 insertions(+) 5fde3e1;2014-01-06 17:26:40 +0530;Merge Baz 772b277;2014-01-06 17:09:42 +0530;Qux 7 files changed, 72 insertions(+), 7 deletions(-) I'm interested in having above format to be displayed like this ed6e0ab;2014-01-07 16:32:39 +0530;Foo;3;14;13 cdfbb10;2014-01-07 14:59:48 +0530;Bar;1;21;0 5fde3e1;2014-01-06 17:26:40 +0530;Merge Baz

How to split strings on carriage return with C#?

帅比萌擦擦* 提交于 2019-11-30 06:18:55
问题 I have an ASP.NET page with a multiline textbox called txbUserName. Then I paste into the textbox 3 names and they are vertically aligned: Jason Ammy Karen I want to be able to somehow take the names and split them into separate strings whenever i detect the carriage return or the new line. i am thinking that an array might be the way to go. Any ideas? thank you. 回答1: string[] result = input.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); This covers both \n and \r

excluding first and last lines from sed /START/,/END/

牧云@^-^@ 提交于 2019-11-29 22:50:24
Consider the input: =sec1= some-line some-other-line foo bar=baz =sec2= c=baz If I wish to process only =sec1= I can for example comment out the section by: sed -e '/=sec1=/,/=[a-z]*=/s:^:#:' < input ... well, almost. This will comment the lines including "=sec1=" and "=sec2=" lines, and the result will be something like: #=sec1= #some-line #some-other-line # #foo #bar=baz # #=sec2= c=baz My question is: What is the easiest way to exclude the start and end lines from a /START/,/END/ range in sed ? I know that for many cases refinement of the "s:::" claws can give solution in this specific case

Insert multiple lines of text before specific line using Bash

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 19:31:34
问题 I am trying to insert a few lines of text before a specific line, but keep getting sed errors when I try to add a new line character. My command looks like: sed -r -i '/Line to insert after/ i Line one to insert \\ second new line to insert \\ third new line to insert' /etc/directory/somefile.txt The error that is reported is: sed: -e expression #1, char 77: unterminated `s' command I've tried, using \n , \\ (as in the example), no character at all, just moving the second line to the next

Insert text on the current place of the cursor in the browser

房东的猫 提交于 2019-11-28 22:08:59
I have a modal window which helps formatting text. I have multiple textareas on the window. The modal should not be attached to a specific textarea, so when I press an Icon in the modal window, I need to insert a string/emoticon etc where-ever the cursor is currently. My question, How do I know in which element (textarea/input/whatever) the cursor is currently in? The latest version of all browsers support document.activeElement. That will tell you which field currently has focus within that window (that's where the cursor is). Then, you'll need to know how to insert text at the current cursor

excluding first and last lines from sed /START/,/END/

隐身守侯 提交于 2019-11-28 19:37:22
问题 Consider the input: =sec1= some-line some-other-line foo bar=baz =sec2= c=baz If I wish to process only =sec1= I can for example comment out the section by: sed -e '/=sec1=/,/=[a-z]*=/s:^:#:' < input ... well, almost. This will comment the lines including "=sec1=" and "=sec2=" lines, and the result will be something like: #=sec1= #some-line #some-other-line # #foo #bar=baz # #=sec2= c=baz My question is: What is the easiest way to exclude the start and end lines from a /START/,/END/ range in

How to split strings on carriage return with C#?

倖福魔咒の 提交于 2019-11-28 16:57:31
I have an ASP.NET page with a multiline textbox called txbUserName. Then I paste into the textbox 3 names and they are vertically aligned: Jason Ammy Karen I want to be able to somehow take the names and split them into separate strings whenever i detect the carriage return or the new line. i am thinking that an array might be the way to go. Any ideas? thank you. string[] result = input.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); This covers both \n and \r\n newline types and removes any empty lines your users may enter. I tested using the following code: string

How to find words from one file in another file?

岁酱吖の 提交于 2019-11-28 13:31:29
In one text file, I have 150 words. I have another text file, which has about 100,000 lines. How can I check for each of the words belonging to the first file whether it is in the second or not? I thought about using grep , but I could not find out how to use it to read each of the words in the original text. Is there any way to do this using awk ? Or another solution? I tried with this shell script, but it matches almost every line: #!/usr/bin/env sh cat words.txt | while read line; do if grep -F "$FILENAME" text.txt then echo "Se encontró $line" fi done Another way I found is: fgrep -w -o -f