What’s the best tool to find and replace regular expressions over multiple files?
Perl. Seriously, it makes sysadmin stuff so much easier. Here’s an example: perl -pi -e ‘s/something/somethingelse/g’ *.log
Perl. Seriously, it makes sysadmin stuff so much easier. Here’s an example: perl -pi -e ‘s/something/somethingelse/g’ *.log
While using regular expressions imparts some performance impact, it should not be as terrible. Note that using String.replaceAll() will compile the regular expression each time you call it. You can avoid that by explicitly using a Pattern object: Pattern p = Pattern.compile(“[,. ]+”); // repeat only the following part: String output = p.matcher(input).replaceAll(“”); Note also … Read more
The main problem you have with all the variations you’ve tried is that both \n and \r are escape characters that are only escaped when you use them in a double-quoted string. In PHP, there is a big difference between ‘\r\n’ and “\r\n”. Note the single-quotes in the first, and double-quotes in the second. So: … Read more
Here is a solution I found. It doesn’t seem very elegant, though: <%@ taglib prefix=”fn” uri=”http://java.sun.com/jsp/jstl/functions” %> <% pageContext.setAttribute(“newLineChar”, “\n”); %> ${fn:replace(item.comments, newLineChar, “; “)}
The fastest way? Iterate over the string and build a second copy in a StringBuilder character by character, only copying one space for each group of spaces. The easier to type Replace variants will create a bucket load of extra strings (or waste time building the regex DFA). Edit with comparison results: Using http://ideone.com/NV6EzU, with … Read more
Do it the other way around: $a = “1,435”; $b = str_replace( ‘,’, ”, $a ); if( is_numeric( $b ) ) { $a = $b; }
Use REPLACE: SELECT REPLACE(t.column, ‘est1’, ‘rest1’) FROM MY_TABLE t If you want to update the values in the table, use: UPDATE MY_TABLE t SET column = REPLACE(t.column, ‘est1’, ‘rest1’)
Try this: website=$(sed ‘s”https://stackoverflow.com/”\\/|g’ <<< $website) Bash actually supports this sort of replacement natively: ${parameter/pattern/string} — replace the first match of pattern with string. ${parameter//pattern/string} — replace all matches of pattern with string. Therefore you can do: website=${website////\\/} Explanation: website=${website // / / \\/} ^ ^ ^ ^ | | | | | | | … Read more
You need to escape your backslash: p.sub(‘gray \\1′, s) alternatively you can use a raw string as you already did for the regex: p.sub(r’gray \1’, s)
If you really must output every values including the NULL ones: select IFNULL(prereq,””) from test