Tag Info

Hot answers tagged

4

The [0-9]* is not useless; it matches any number (0-9) that show up before the even number range ([02468]). This is to take into account multi-digit even numbers. For e.g., if you didn't have ^[0-9]* anchored to beginning of your pattern, it would not match: 92 910 308 20 The other pattern you mentioned (/^[02468]/) would only match anything that begins ...


3

Your expression is telling sed to match either <?xml.*><Haystack or Foo. The Regex engine uses the capturing parenthesis to tell how far left or right to extend the or operator. (If you used a PCRE engine, then you could use non-capturing parenthesis.) Original, problematic code: echo "20150310 21:12:01.846338::: <?xml ...


3

$ file corncob_lowercase.txt corncob_lowercase.txt: ASCII text, with CRLF line terminators Probably the DOS line endings are the source of your problem. CR is counting as a character for at least some purposes. Run it through dos2unix, or tr -d '\r', before greping.


3

New GNU sed (with parameter -z) do it one pass: sed -z 's/\n\(\n\|[A-Z0-9][)a-z]\)/ \1/g' DATA


2

If you want to remove things like \" and \"{ and }, you will have to preprocess your input file with a tool like sed before feeding it into bib2bib. Example: sed -e 's/\\"\{\|\\"\|\}// input.bib > input.bib.preprocessed Or to specifically convert things like \"{u} into u: sed -e 's/\\"{\(.\)}/\1/' -e 's/\\"//' input.bib > input.bib.preprocessed ...


2

Yes you can, with capture groups. Basically, you wrap the parts of the pattern with \(...\) and reference that in the replacement part with \1 etc.: :%s/Uset\(\d\d\)-\(\d\)/USet\1\2 Since you only want to remove a single part of the pattern, a shorter option is restricting the actual match (but still asserting that the stuff around is also there) via \zs ...


2

Due to the fact that SSL is end-to-end encryption, a proxy such as Squid normally knows much less about an HTTPS request than it does on HTTP (http://wiki.squid-cache.org/Features/HTTPS#CONNECT_tunnel): [Many] common parts of the request URL do not exist in a CONNECT request: the URL scheme or protocol (e.g., http://, https://, ftp://, voip://, ...


1

OK, I think I’ve got it.  Your Source: (?<group>.*/).*\n regex is capturing, in the group group, everything after the Source:  up through the last / on the line.  So, for your example, it is capturing /disk/media/Camera/.  To capture the JPEG image filename, you want Source: .*/(?<group>.*)\n… OK, here we go again.  I believe that you are ...


1

In any POSIX-compatible shell you can do: case $line in (*"$PWD"*) : whatever your then block had ;;esac This works in bash, dash, and just about any other shell you can name.


1

Yes, recent versions of bash can do this: $ pwd /home/terdon $ line="I'm in /home/terdon" $ [[ "$line" =~ "$PWD"$ ]] && echo yes yes The same syntax works in zsh and ksh but not in dash. As far as I know, dash has no such capabilities. Note that your regex is checking whether the variable $line ends with $PWD. To check if $PWD matches anywhere in ...


1

A fully portable solution could look like: n=' ';printf %s\\n muller wright dummy >/tmp/patterns tr '[:lower:][:upper:]' '[:upper:][:lower:]' </tmp/patterns | paste '-d\n\n' - /tmp/patterns | sed "N;s/./\\$n&/;:ul$n s/\(\n\)\(.\)\(.*\n\)\(.\)/\2\4\1\3/;tul"' s/\n//g;s/../[{}\\"]*[&]/g' The output from that last sed looks like: ...


1

Several things: . is a special character, therefore it has to be escaped: ^10\.20\.30\.([0-1][0-9][0-9]|2[00]) 2[00]matches 20, not 200: ^10\.20\.30\.([0-1][0-9][0-9]|200) You have to handle single-digit and double-digit numbers separately: ^10\.20\.30\.([0-1][0-9][0-9]|200|[0-9][^0-9]|[0-9][0-9][^0-9]) This gives the correct result: $ grep -vE ...


1

(Edited solution due to feedback about actual requirements...) It's probably easier to understand and implement if you perform it in four steps; replace \n\n by some unused [control] character (say \a), add an \a at the front of a line with an \a, then delete all \n, and finally replace the \a by \n again. (Define a vim macro if you need that replacement ...


1

I like playing with regular expressions but truly I don't feel like I am a master of it. I would do what you want in 2 steps: $ perl -i.bak -0pe 's/\n([A-Z])/ \1/g' DATA $ less DATA 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b And now just remove empty lines, for example with sed or flush-lines function ...


1

Using awk + sed perhaps? For: $ cat quiz 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b Run $ awk NF=NF RS= OFS=' ' quiz | sed 's/\([a-z]$\)/\n\1/' 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b


1

This is because the match pattern .* is what is known as a greedy match, meaning that it will return the largest string to match your search pattern. What you would want to do is to use a non-greedy (or lazy) match, which returns the shortest string to match your pattern. You can do this by changing your greedy match from .* to .*?. However, grep typically ...


1

You were almost there, try this: sudo sed 's/,\([0-9]\{1,2\}\)/,\1\)/g' filename Here in addition to your command i have just added \{1,2\} which matches the previous regex between one to two times i.e. from a minimum of one time to a maximum of two times. \([0-9]\{1,2\}\) explained: [0-9] will match a single digit between 0 to 9 {1,2} will match the ...


1

To search for a parenthesis character, pass backslash+parenthesis to ack. Both backslash and parentheses are special in the shell, so you need to quote them when you're entering them in a shell script or on the command line. The simplest form of quoting is with single quotes: this tells the shell to pass everything through literally except single quotes ...


1

Try: diff -b -I '^#' -I '^ #' file1 file2 Please note that the regex has to match the corresponding line in both files and it matches every changed line in the hunk in order to work, otherwise it'll still show the difference. Use single quotes to protect pattern from shell expanding and to escape the regex-reserved characters (e.g. brackets). We can ...



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