text-manipulation

Edit configuration file through python

一曲冷凌霜 提交于 2019-12-05 04:03:50
I need to edit a configuration file through python and i tried searching on stackoverflow and google and they don't cover my situation, since i need to replace lines in the file and perform matches in my search. Also, what i found covers how to do it for one line, i will be performing at least 8 line replacements in the file and I would like to know if there is a cleaner and more elegant way of doing this than putting 10 replace(foo, bar) lines altogether. I need to "match" lines like "ENABLEPRINTER", "PRINTERLIST", "PRNT1.PORT". I want to match thesse text and ignore whatever follows (ex: "

Shift a region or line in emacs

孤街浪徒 提交于 2019-12-03 07:30:26
问题 I'm looking for a way in emacs to shift text to the right or to the left by n spaces. A similar functionality that it in vim << or >> . It should work on a region or if no region is selected on a current line and not move the cursor from its current location. The solution from EmacsWiki does not work very well as the M-x indent-rigidly since it somewhat remembers the last region used and shifts that one instead. The closest seems to be the one here but I did not managed to make it work. I'm

sed - comment a matching line and x lines after it

假如想象 提交于 2019-12-03 07:22:54
问题 I need help with using sed to comment a matching lines and 4 lines which follows it. in a text file. my text file is like this: [myprocess-a] property1=1 property2=2 property3=3 property4=4 [anotherprocess-b] property1=gffgg property3=gjdl property2=red property4=djfjf [myprocess-b] property1=1 property4=4 property2=2 property3=3 I want to prefix # to all the lines having text '[myprocess' and 4 lines that follows it expected output: #[myprocess-a] #property1=1 #property2=2 #property3=3

Shift a region or line in emacs

蹲街弑〆低调 提交于 2019-12-02 21:01:14
I'm looking for a way in emacs to shift text to the right or to the left by n spaces. A similar functionality that it in vim << or >> . It should work on a region or if no region is selected on a current line and not move the cursor from its current location. The solution from EmacsWiki does not work very well as the M-x indent-rigidly since it somewhat remembers the last region used and shifts that one instead. The closest seems to be the one here but I did not managed to make it work. I'm not a lisp developer so it's difficult to modify the code. I will appreciate any help. Thanks! Maybe

sed - comment a matching line and x lines after it

怎甘沉沦 提交于 2019-12-02 20:54:33
I need help with using sed to comment a matching lines and 4 lines which follows it. in a text file. my text file is like this: [myprocess-a] property1=1 property2=2 property3=3 property4=4 [anotherprocess-b] property1=gffgg property3=gjdl property2=red property4=djfjf [myprocess-b] property1=1 property4=4 property2=2 property3=3 I want to prefix # to all the lines having text '[myprocess' and 4 lines that follows it expected output: #[myprocess-a] #property1=1 #property2=2 #property3=3 #property4=4 [anotherprocess-b] property1=gffgg property3=gjdl property2=red property4=djfjf #[myprocess-b]

Decoding unknown encoded Traditional Chinese character strings using Python

牧云@^-^@ 提交于 2019-12-02 11:42:09
问题 Hi I have a website that is in Traditional Chinese and when I check the site statistics it tell me that the search term for the website is å%8f°å%8d%97 親å­%90é¤%90廳 which obviously makes no sense to me. My question is what is this encoding called? And is there a way to use Python to decode this character string. Thank you. 回答1: It is called a mutt encoding; the underlying bytes have been mangled beyond their original meaning and they are no longer a real encoding. It was once URL-quoted

Convert numbers to words with VBA

旧巷老猫 提交于 2019-12-01 21:49:47
I have a column of numbers. In the next column, I want the text/word conversion of the numbers. Example : 123.561 would convert to One hundred twenty three point five six one . I do not want to convert to currency, just number to text, with any number of decimal places. How can I do this? ashleedawg Edit: I've adapted the procedure below to non-currency, unlimited decimal places. Edit 2 considers internationalisation via two changes in (1) Function SpellNumber and (2) Function fractionWords to make code work with other decimal separators (e.g. colon in middle Europe) ' - see comment Example:

Java regex: newline + white space

被刻印的时光 ゝ 提交于 2019-12-01 15:09:24
should be simple, but I'm going crazy with it. Given a text like: line number 1 line number 2 line number 2A line number 3 line number 3A line number 3B line number 4 I need the Java regex that deletes the line terminators then the new line begin with space, so that the sample text above become: line number 1 line number 2line number 2A line number 3line number 3Aline number 3B line number 4 yourString.replaceAll("\n ", " "); this wont help? String res = orig.replaceAll("[\\r\\n]+\\s", ""); Perhaps to make it cross-platform: String pattern = System.getProperty("line.separator") + " "; string

Java regex: newline + white space

人盡茶涼 提交于 2019-12-01 14:46:44
问题 should be simple, but I'm going crazy with it. Given a text like: line number 1 line number 2 line number 2A line number 3 line number 3A line number 3B line number 4 I need the Java regex that deletes the line terminators then the new line begin with space, so that the sample text above become: line number 1 line number 2line number 2A line number 3line number 3Aline number 3B line number 4 回答1: yourString.replaceAll("\n ", " "); this wont help? 回答2: String res = orig.replaceAll("[\\r\\n]+\

Find url in plain text and insert HTML A markups

我只是一个虾纸丫 提交于 2019-12-01 00:22:44
I have text with URL and I need to wrap them with HTML A markup, how to do that in c#? Example, I have My text and url http://www.google.com The end. I would like to get My text and url <a href="http://www.google.com">http://www.google.com</a> The end. nhu You can use a regex for this. If you need a better Regex you can search for it here http://regexlib.com/Search.aspx?k=url My quick solution for this would be this: string mystring = "My text and url http://www.google.com The end."; Regex urlRx = new Regex(@"(?<url>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)", RegexOptions.IgnoreCase);