blank-line

Windows Batch: How to keep empty lines with loop for /f

三世轮回 提交于 2019-11-29 11:38:45
I'm searching how to keep empty lines when I browse a file with a for loop. for /f "tokens=1* delims=[" %%i in ('type "test1.txt" ^| find /v /n ""') do ( SET tmp=%%i echo !tmp! >> test2.txt ) Actually it works for everybody, but as far as I'm concerned it does not work. For instance if test1.txt content is : Hello I come from France I live in Paris I'm sorry I don't know english, could we speak french please ? If it doesn't bother you Thank you Result in test2.txt will be : [1 [2 [3 [4 [5 [6 [7 If I put off the "1" near the star "*", result is : [1]Hello I come from France [2]I live in Paris

Remove all blank spaces and empty lines

孤人 提交于 2019-11-28 13:32:01
How to remove all blank spaces and empty lines from a txt File using Java SE? Input: qwe qweqwe qwe qwe Output: qwe qweqwe qwe qwe Thanks! JJ. How about something like this: FileReader fr = new FileReader("infile.txt"); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("outfile.txt"); String line; while((line = br.readLine()) != null) { line = line.trim(); // remove leading and trailing whitespace if (!line.equals("")) // don't write out blank lines { fw.write(line, 0, line.length()); } } fr.close(); fw.close(); Note - not tested, may not be perfect syntax but gives

python csv reader ignore blank row

泪湿孤枕 提交于 2019-11-28 06:53:13
问题 Im using the pythons csv reader . How can I use the following code in such a way that it ignores blank lines. import csv f1 = open ("ted.csv") oldFile1 = csv.reader(f1, delimiter=',', quotechar='"') oldList1 = list(oldFile1) f2 = open ("ted2.csv") newFile2 = csv.reader(f2, delimiter=',', quotechar='"') newList2 = list(newFile2) f1.close() f2.close() with open("ted.csv") as f1, open("ted2.csv") as f2, open('foo.csv', 'w') as out: r1, r2 = csv.reader(f1), csv.reader(f2) st = set((row[0], row[3]

Windows Batch: How to keep empty lines with loop for /f

大兔子大兔子 提交于 2019-11-28 04:39:56
问题 I'm searching how to keep empty lines when I browse a file with a for loop. for /f "tokens=1* delims=[" %%i in ('type "test1.txt" ^| find /v /n ""') do ( SET tmp=%%i echo !tmp! >> test2.txt ) Actually it works for everybody, but as far as I'm concerned it does not work. For instance if test1.txt content is : Hello I come from France I live in Paris I'm sorry I don't know english, could we speak french please ? If it doesn't bother you Thank you Result in test2.txt will be : [1 [2 [3 [4 [5 [6

JavaScript: how to use a regular expression to remove blank lines from a string? [closed]

爱⌒轻易说出口 提交于 2019-11-27 18:42:30
I need to use JavaScript to remove blank lines in a HTML text box. The blank lines can be at anywhere in the textarea element. A blank line can be just a return or white spaces plus return. I am expecting a regular expression solution to this. Here are some I tried, but they are not working and cannot figure out why: /^\s*\r?\n/g /^\s*\r?\n$/g Edit 1 It appears that the solution (I modified it a little) suggested by aaronman and m.buettner works: string.replace(/^\s*\n/gm, "") Can someone tell why my first regular expression is not working? Edit 2 After reading all useful answers, I came up

How to remove blank lines from a Unix file

為{幸葍}努か 提交于 2019-11-27 17:58:37
I need to remove all the blank lines from an input file and write into an output file. Here is my data as below. 11216,33,1032747,64310,1,0,0,1.878,0,0,0,1,1,1.087,5,1,1,18-JAN-13,000603221321 11216,33,1033196,31300,1,0,0,1.5391,0,0,0,1,1,1.054,5,1,1,18-JAN-13,059762153003 11216,33,1033246,31300,1,0,0,1.5391,0,0,0,1,1,1.054,5,1,1,18-JAN-13,000603211032 11216,33,1033280,31118,1,0,0,1.5513,0,0,0,1,1,1.115,5,1,1,18-JAN-13,055111034001 11216,33,1033287,31118,1,0,0,1.5513,0,0,0,1,1,1.115,5,1,1,18-JAN-13,000378689701 11216,33,1033358,31118,1,0,0,1.5513,0,0,0,1,1,1.115,5,1,1,18-JAN-13,000093737301

How to remove newlines from beginning and end of a string (Java)?

断了今生、忘了曾经 提交于 2019-11-27 12:15:44
I have a string that contains some text followed by a blank line. What's the best way to keep the part with text, but remove the whitespace newline from the end? Use String.trim() method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string. String trimmedString = myString.trim(); String.replaceAll("[\n\r]", ""); If your string is potentially null , consider using StringUtils.trim() - the null-safe version of String.trim() . String trimStartEnd = "\n TestString1 linebreak1\nlinebreak2\nlinebreak3\n TestString2 \n"; System.out.println("Original String : ["

JavaScript: how to use a regular expression to remove blank lines from a string? [closed]

北慕城南 提交于 2019-11-27 04:17:19
问题 I need to use JavaScript to remove blank lines in a HTML text box. The blank lines can be at anywhere in the textarea element. A blank line can be just a return or white spaces plus return. I am expecting a regular expression solution to this. Here are some I tried, but they are not working and cannot figure out why: /^\s*\r?\n/g /^\s*\r?\n$/g Edit 1 It appears that the solution (I modified it a little) suggested by aaronman and m.buettner works: string.replace(/^\s*\n/gm, "") Can someone

How to automatically insert a blank row after a group of data

送分小仙女□ 提交于 2019-11-26 22:31:09
I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question. I want to simply add a row after each distinct datum in column1 (simplest way, using excel, thanks). _ CURRENT TABLE: column1 | column2 | column3 ---------------------------------- A | small | blue A | small | orange A | small | yellow B | med | yellow B | med | blue C | large | green D | large | green D | small | pink _ DESIRED TABLE Note: the blank row after each distinct column1 column1 | column2 | column3 ---------------------------------- A | small | blue A |

How to remove blank lines from a Unix file

六月ゝ 毕业季﹏ 提交于 2019-11-26 19:14:21
问题 I need to remove all the blank lines from an input file and write into an output file. Here is my data as below. 11216,33,1032747,64310,1,0,0,1.878,0,0,0,1,1,1.087,5,1,1,18-JAN-13,000603221321 11216,33,1033196,31300,1,0,0,1.5391,0,0,0,1,1,1.054,5,1,1,18-JAN-13,059762153003 11216,33,1033246,31300,1,0,0,1.5391,0,0,0,1,1,1.054,5,1,1,18-JAN-13,000603211032 11216,33,1033280,31118,1,0,0,1.5513,0,0,0,1,1,1.115,5,1,1,18-JAN-13,055111034001 11216,33,1033287,31118,1,0,0,1.5513,0,0,0,1,1,1.115,5,1,1,18