Tag Info

Hot answers tagged

6

The following RegEx tests for a variable amount of lines before the XXXXXXXX line and returns them in the first capture group. ((.*\n){2})XXXXXXXX (.*\n) tests for a string ending with \n, a newline. {2} quantifies this 2 times. () around that makes sure all lines come in one capture group. XXXXXXXX is the string that the text has to end with. Now in ...


5

To delete all files ending in .jpg (case-insensitive) except for files with sample in the file name (case-insensitive: find . ! -iname '*sample*' -iname '*.jpg' -delete This recurses through all directories in the tree starting at the current directory. How it works: . This specifies that we start with the current directory. ! -iname '*sample*' ...


2

Your regexp captures the complete input string abcde captures the 'e' and replaces that by \e. You probably want something more like this: :s/\S/\\&/g


2

A possible solution is: .*<matching pattern>(.*\r?\n){<N+1>} where N is the number of lines I want to remove after the line containing the pattern. For the example given, this translates in: .*bbbb(.*\r?\n){6} That's how it looks in grepWin: Side notes: In the tab "The regex search string matches" also the 5aldfkld line is marked to be ...


2

Shells mostly don't provide the usual regexp syntax, but wildcard “glob” patterns. Basic shell wildcards aren't as powerful as regular expressions; for example, the regexp .* (any sequence of characters) is equivalent to the glob pattern * but the regexp a* (any sequence of a's) has no glob pattern equivalent in plain sh. See Why does my regular expression ...


2

Find is used for filenames. Grep is used to search within a file or files. So for this, we'll use grep. From the root directory you wish to search in, run: grep -r 'shareEventHandler.php\|repToolBroker.php\|loginProctor.php\|messageBroker.php\|emailBroker.php' . grep - search app -r recursive search from this directory down Use "\|" between search terms ...


1

When immediately following the opening square bracket, the closing one just means itself ]. The next opening square bracket is also simply meaning its own character [. $ echo "a[b" | grep '[]]' $ echo "a[b" | grep '[[]' a[b $ echo "a[b" | grep '[]' grep: Unmatched [ or [^


1

The patterns are written this way to avoid the need to escape the ] character (and also the hyphen) within the character class being defined. Un-escaped, ] closes a character class. However, if you follow [ immediately with ], it is a special construction that indicates that the 'closing square bracket' is to be included in the character class. Similarly, ...


1

You can use (\r\n)*<script.*?/script>(\r\n)* to remove the script tags along with its leading and trailing blank lines.


1

An awk solution: awk '/bbbb/ {i=5; next} {if (i>0) i--; else print}' When it detects the pattern you're looking for, it sets i (which is a countdown counter) to 5, and skips the rest of the processing (i.e., skips to the next line of input).  In particular, it does not print the line.  (Saying /bbbb/ {i=5+1} for the first part would be equivalent; ...


1

You can use negative lookahead like this. Search (?!<CID>.*BUS..*.DKV</CID>(.*?))<SizeIsMeasuredLineLine>false</SizeIsMeasuredLineLine> and replace with <SizeIsMeasuredLineLine>false</SizeIsMeasuredLineLine> Regular Expression , matching . newline Negative Lookahead (?!a) and Negative Lookbehind (?<!a), Are also ...


1

In bash, you can use shopt -s extglob to enable negative matching: rm !(*[Ss]ample*).jpg To match subfolders too, turn on shopt -s globstar and use the double star: rm **/!(*[Ss]ample*).jpg


1

As far as I know you can use Word to search for an italicised string and replace it with a non-italicised one, but you can't replace it with a partially italicised string. So the following two-step workaround might be the only thing you can do short of using VBA: Search for "See, e.g.," (Font: Italic) and replace all with "See, e.g.~~" (Font: Italic) ...


1

Word doesn't accept ^p in regular expressions, you need to use ^13 instead. So your replace with field will be: ^13^13\1


1

I think the look-aheads are overkill in this case, and you would be better off using word boundaries with the ignorecase option, \brocket\b In other words, in python: >>> x="rocket's" >>> y="rocket1." >>> c=re.compile(r"\brocket\b",re.I) # with the ignorecase option >>> c.findall(y) [] >>> c.findall(x) ...


1

I can't get it to work with zmv either. There must be a way but it escapes me. However, zmv is not the only tool that can do something like that. You can also use rename. If you're using zsh $ rename -n 's/-[A-Za-z0-9]{32}//' **/* another-directory/style-748reiodlpqwerntaerwerwerexfzsdf.js.gz renamed as another-directory/style.js.gz ...



Only top voted, non community-wiki answers of a minimum length are eligible