substitution

using command substitution inside a sed script, with arguments

感情迁移 提交于 2019-12-05 15:32:50
I am trying to write a short script in which I use sed to search a stream, then perform a substitution on the stream based on the results of a shell function, which requires arguments from sed, e.g. #!/bin/sh function test { echo "running test" echo $1 } sed -n -e "s/.*\(00\).*/$(test)/p" < testfile.txt where testfile.txt contains: 1234 2345 3006 4567 (with newlines between each; they are getting removed by your sites formatting). So ok that script works for me (output "running test"), but obviously has no arguments passed to test. I would like the sed line to be something like: sed -n -e "s/.

Bash double process substitution gives bad file descriptor

孤者浪人 提交于 2019-12-05 04:10:22
When I try to refer to two process substitution pipes in a bash function, only the first one referenced works. The second one gives a "bad file descriptor" error like so: $ foo(){ > cat "$1" > cat "$2" > } $ foo <(echo hi) <(echo bye) hi cat: /dev/fd/62: Bad file descriptor $ It appears that the second pipe is dropped once one is referenced, but a) I cannot seem to confirm this behavior in any documentation and b) I wish it wouldn't. =) Any ideas on what I'm doing wrong? FWIW I'm doing this to make a wrapper to use Mac OS X's FileMerge graphical diff tool instead of the command line one, which

Inline regex replacement in perl

寵の児 提交于 2019-12-05 01:43:45
Is there a way to replace text with a regex inline, rather than taking the text from a variable and storing it in a variable? I'm a perl beginner. I often find myself writing my $foo = $bar; $foo =~ s/regex/replacement/; doStuff($foo) where I'd really like to write doStuff($bar->replace(s/regex/replacement/)); or the like, rather than using a temporary variable and three lines. Is there a way to do this? Obviously when the regex is sufficiently complicated it makes sense to split it out so it can be better explained, but when it's just s/\s//g it feels wrong to clutter the code with additional

How to split text into multiple lines based on a pattern using Vim?

半世苍凉 提交于 2019-12-04 23:28:00
Suppose you have this text: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3 = "Mike"; age3 = 36; ... and you want to split each line into two lines to give a result like this: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3 = "Mike"; age3 = 36; ... How would you automate this operation? Some notes: I already tried the following method: (1) Select the text in virtual-vode, (2) Execute :'<,'>:norm ^3f r^M ***, but it doesn't work correctly; it splits only half of the lines, because after every line is broken, the next repetition of the command applies to the rest of the

Prepend file names with plus sign

做~自己de王妃 提交于 2019-12-04 20:57:16
问题 I want to add a + (plus sign) before all the occurrences of image names in a huge file, using sed . This is an example of one line: DAUSSI-H22-14K White Gold-Princess-1.00ct-G-SI1orH-VS2-EGL-mm-3.5,,H22,,7050,5720,3/5/2012 7:34,,,1,,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5,henri-daussi-h22-diamond-halo-engagement-ring-14k-white-gold-width--mm-style-princess-1-00ct-g-si1-or-h-vs2-egl-size-3-5.html,Henri Daussi H22

Regular Expression for Conditional Substitution of Angle Brackets

余生颓废 提交于 2019-12-04 19:54:24
Is it possible to create a single regexp to replace < and > with their entity equivalents in Komodo Edit? s/<|>/<|>/ I'm guessing that you may have to convert & to & and so on. If this is the case there's most likely a library or function in whichever language/platform you're using (e.g. in Java check out StringEscapeUtils ). Indicate which language you're using and someone here will no doubt point you to something appropriate. It is easy in to do this in just about any language without using regex: PHP: $xml = str_replace(array('>', '<'), array('>','<'), $xml); Python: xml = xml.replace('>',

vim replace character to \n

我与影子孤独终老i 提交于 2019-12-04 18:26:02
问题 I need replace all ; to \n , but :%s/;/\n/gc not works 回答1: See http://vim.wikia.com/wiki/Search_and_replace When searching: \n is newline, \r is CR (carriage return = Ctrl-M = ^M) When replacing: \r is newline, \n is a null byte (0x00). 回答2: You need to use \r as the replacement instead: :%s/;/\r/gc 来源: https://stackoverflow.com/questions/3965883/vim-replace-character-to-n

How do I avoid repetition in Java ResourceBundle strings?

不羁的心 提交于 2019-12-04 09:08:38
问题 We had a lot of strings which contained the same sub-string, from sentences about checking the log or how to contact support, to branding-like strings containing the company or product name. The repetition was causing a few issues for ourselves (primarily typos or copy/paste errors) but it also causes issues in that it increases the amount of text our translator has to translate. The solution I came up with went something like this: public class ExpandingResourceBundleControl extends

Python Replace Single Quotes Except Apostrophes

大兔子大兔子 提交于 2019-12-04 05:03:02
问题 I am performing the following operations on lists of words. I read lines in from a Project Gutenberg text file, split each line on spaces, perform general punctuation substitution, and then print each word and punctuation tag on its own line for further processing later. I am unsure how to replace every single quote with a tag or excepting all apostrophes. My current method is to use a compiled regex: apo = re.compile("[A-Za-z]'[A-Za-z]") and perform the following operation: if "'" in word

why process substitution does not always work with while loop in bash?

99封情书 提交于 2019-12-04 02:58:08
The process substitution works with filenames fine, e.g. both $ cat <FILENAME and $ while read i; do echo $i; done <FILENAME work. But if instead of FILENAME we use echo command (or any other, which generates output to stdout), cat continues to work $ cat <(echo XXX) XXX while the loop $ while read i; do echo $i; done <(echo XXX) bash: syntax error near unexpected token `<(echo XXX)' produces error. Any ideas why? Note: < filename is not process substitution. It's a redirection . Process substitution has the format <( command ) . Process substitution substitutes the name of a process for the <