Tag Info

New answers tagged

0

You can do... while read line do line=${line%%[!0-9]*} [ -n "$line" ] || continue : work w/ digits at line's head done Alternatively - and probably faster - you can do: tr -cs 0-9\\n \ | while IFS=\ read num na do ${num:+":"} continue : work w/ first seq of digits on line done Or is if you want to ignore completely any line ...


0

If the text is not too big you can flatten the string by replacing all the newline characters with some safe special token - then perform normal sed operations on it and explode the tokens back to newlines when you are done.


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.


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 ...


0

You can use the idea from this thread on SF: Need help grepping postfix log. First you should search all possible queue IDS matching your criteria. To do that you can use command grep 'from=<sachin@tendulkar.glbl>' /var/log/maillog | cut -d ' ' -f 6 or grep 'to=<recipient@example.com' /var/log/maillog | cut -d ' ' -f 6 Then you can use ...


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: ...


0

I fixed my problem my writing ssl_bump server-first all and removing ssl_bump allow all. I'm not sure if it contributed to fixing the problem, but I also put these lines into my terminal: /sbin/iptables -t nat -A PREROUTING -p TCP -s 127.0.0.1 --dport 80 -j REDIRECT --to-port 3128 /sbin/iptables -t nat -A PREROUTING -p TCP -s 127.0.0.1 --dport 443 -j ...


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 ...


0

You haven't mentioned in what way you have your data available. To remove lines containing the posted patterns you can use grep: grep -v -E '(muller|M\\"uller|M\\"{u}ller)' (Note that the \ needs another escape.) To match the inverse, lines with the given patterns, omit the -v. To define the regular expressions in a file use grep's option -f, as in: ...


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 ...


0

I found a solution myself using substring matching thanks to the vim help: :%s/\(USet\d\d\)-\(\d\)/\1\2/gc


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://, ...


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 ...


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 ...


0

Try the following. M-x query-replace-regexp RET \(^.*{$\) RET .newclass \1 RET The actual regexp I am using for matching is ^.*{$ to match full lines the end with a { so the I can prepend the new class. It is enclosed within \( and \) so that the captured group can be reused in the Replace pattern. In the replace pattern we use \1 to refer to the ...


0

This should get what you want, I think: grep -vE '10\.20\.30\.(1|..?,|200) ' <<\IN 10.20.30.150,20 10.20.30.134,20 10.20.30.201,20 10.20.30.5,20 10.20.30.250,20 10.20.30.42,20 222.233.201.5,20 10.233.201.5,20 111.233.201.5,20 IN Basically you just have to exclude any match for 10.20.30 with a final octet fewer than three characters, that begins with ...


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 ...


0

You can set priorities using a "strength" value. From magic(4): An optional strength can be supplied on a separate line which refers to the current magic description using the following format: !:strength OP VALUE The operand OP can be: +, -, *, or / and VALUE is a constant between 0 and 255. This constant is applied using the specified ...


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 ...


3

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


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


0

The syntax for a negative lookahead in vim is like this: :s/\n\n\@!//gN Where N is a number of lines. In perl, it would be: s/\n(?!\n)// However, I think you'll find that's not exactly what you are trying to do, since in your example output, c and b are both on a line of their own. If you replace all newlines not followed by another newline, they ...


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 ...


0

Often vim comes with Perl linked. The possibility of using perl (or similar) in Vim, may by relevant. When you have +perl, you can use :perldo + @steeldriver solution (in fact a slightly variation): :perldo s/\\cite{(?:\d+,)*\K(\d+)-(\d+)(?=(,.*?)?})/sprintf "%s",join(",", $1..$2)/e


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 ...


0

i don't know the exact error you get, but here it works using escaped parenthesis ("\(") $ cat > test.c <<EOF int main() { return 0; } EOF $ ack '\(' test.c int main() { $


0

Sounds like you want something like: awk 'BEGIN {RS="\n\n"} /What exactly is Free/' br.txt This should print the entire paragraphs where the text is found (RS="\n\n").


1

To remove all words from a line that begin with a number with sed you can do: sed 'x;s/.*//;G s/[[:space:]][[:punct:]]\{0,1\}[0-9][^[:space:]]*//g s/\n//' ...or, if you wanted only words which do not begin with numbers printed each on a separate line: sed 'y/!\t "'"'?/\n\n\n\n\n\n/;/^[_[:alpha:]]/P;D" ...the above should do fairly well. ...


2

It depends how do you define a string (e.g. if you count punctuation characters to string or not). Nevertheless you may start from something like grep -Po '\b[^[:digit:]].*?\b' file


5

grep -v '^[0-9]' Will output all the lines that do not (-v) match lines beginning ^ with a number [0-9] For example $ cat test string string123 123string 1string2 $ grep -v '^[0-9]' test string string123 or if you want to remove all the words that begin with a digit sed 's/[[:<:]][[:digit:]][[:alnum:]_]*[[:>:]]//g' or with shortcuts and ...



Top 50 recent answers are included