delimiter

How do I extract lines between two line delimiters in Perl?

孤人 提交于 2019-11-28 07:42:07
I have an ASCII log file with some content I would like to extract. I've never taken time to learn Perl properly, but I figure this is a good tool for this task. The file is structured like this: ... ... some garbage ... ... garbage START what i want is on different lines END ... ... more garbage ... next one START more stuff I want, again spread through multiple lines END ... more garbage So, I'm looking for a way to extract the lines between each START and END delimiter strings. How can I do this? So far, I've only found some examples on how to print a line with the START string, or other

How can I split by 1 or more occurrences of a delimiter in Python?

老子叫甜甜 提交于 2019-11-28 07:18:39
I have a formatted string from a log file, which looks like: >>> a="test result" That is, the test and the result are split by some spaces - it was probably created using formatted string which gave test some constant spacing. Simple splitting won't do the trick: >>> a.split(" ") ['test', '', '', '', ... '', '', '', '', '', '', '', '', '', '', '', 'result'] split(DELIMITER, COUNT) cleared some unnecessary values: >>> a.split(" ",1) ['test', ' result'] This helped - but of course, I really need: ['test', 'result'] I can use split() followed by map + strip() , but I wondered if there is a more

Parsing HTML source code using AppleScript

孤人 提交于 2019-11-28 06:48:22
问题 I'm trying to parse an HTML file which I have converted to a TXT file inside of Automator. I previously downloaded the HTML file from a website using Automator, and I am now struggling to parse the source code. Preferably, I want to take the information of just the table and I need to repeat this action for 1800 different HTML files. Here is an example of the source code: </head> <body> <div id="header"> <div class="wrapper"> <span class="access"> <div id="fb-root"></div> <span class="access"

String delimiter in string.split method

一世执手 提交于 2019-11-28 05:42:13
I have following data: 1||1||Abdul-Jabbar||Karim||1996||1974 I want to delimit the tokens. Here the delimiter is "||" . My delimiter setter is: public void setDelimiter(String delimiter) { char[] c = delimiter.toCharArray(); this.delimiter = "\"" + "\\" + c[0] + "\\" + c[1] + "\""; System.out.println("Delimiter string is: " + this.delimiter); } However, String[] tokens = line.split(delimiter); is not giving the required result. There is no need to set the delimiter by breaking it up in pieces like you have done. Here is a complete program you can compile and run: import java.util.Arrays;

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

Multiple delimiters in Scanner class of Java

假装没事ソ 提交于 2019-11-28 00:46:05
How do I use the useDelimiter() method of the Scanner class to use both the comma (,) and the new line character (\n) as delimiters? I am parsing some text from a csv file. Scanner s = new Scanner("hello, world \n hello world"); s.useDelimiter(",|\\n"); while(s.hasNext()){ System.out.println(s.next()); } Output hello world hello world JavaDoc How about useDelimiter(",|\\n"); useDelimiter takes a regex pattern, so, it would be something like ",|\n" Jigar is absolutely correct. But if it doesn't work, try ",|\\r" since most text files have \r\n instead of just \n Using Scan Delimiters for Excel

Splitting a string with multiple delimiters in Python

余生长醉 提交于 2019-11-27 23:38:29
问题 I'm using regular expressions to split a string using multiple delimiters. But if two of my delimiters occur next to each other in the string, it puts an empty string in the resulting list. For example: re.split(',|;', "This,is;a,;string") Results in ['This', 'is', 'a', '', 'string'] Is there any way to avoid getting '' in my list without adding ,; as a delimiter? 回答1: Try this: import re re.split(r'[,;]+', 'This,is;a,;string') > ['This', 'is', 'a', 'string'] 来源: https://stackoverflow.com

MySQL delimiter syntax error

半城伤御伤魂 提交于 2019-11-27 23:09:40
I'm trying to change the MySQL command delimiter so I can create a procedure with multiple commands in it. However, the delimiter command does not seem to be recognised on MySQL 5.1.47. I tested it on MySQL 5.0.91, and it did work there. DELIMITER //; DELIMITER ;// I'm trying to run this from phpmyadmin, in both situations. Using 5.0.91 instead isn't an option because I need to use events ( CREATE EVENT ). Error message: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //' at line 1 Is there

Delphi: StringList Delimiter is always a space character even if Delimiter is set

无人久伴 提交于 2019-11-27 20:58:16
I am having trouble with the delimiter in the TStringList Class. Take a look: var s: string; sl: TStringList; begin sl := TStringList.Create; s := 'Users^foo bar^bar foo^foobar^barfoo'; sl.Delimiter := '^'; sl.DelimitedText := s; ShowMessage(sl[1]); end; sl[1] SHOULD return 'foo bar' sl[1] DOES return 'foo' It seems that the delimiter is now '^' AND ' ' Any ideas? Roee Adler You should set s1.StrictDelimiter := True for spaces not to be considered delimiters, more info here . Since you work in a version that does not support the above (as was clarified after the answer was submitted), you have

Can I import a CSV file and automatically infer the delimiter?

此生再无相见时 提交于 2019-11-27 19:58:55
I want to import two kinds of CSV files, some use ";" for delimiter and others use ",". So far I have been switching between the next two lines: reader=csv.reader(f,delimiter=';') or reader=csv.reader(f,delimiter=',') Is it possible not to specify the delimiter and to let the program check for the right delimiter? The solutions below (Blender and sharth) seem to work well for comma-separated files (generated with Libroffice) but not for semicolon-separated files (generated with MS Office). Here are the first lines of one semicolon-separated file: ReleveAnnee;ReleveMois;NoOrdre;TitreRMC