___ ___ erkimt Exclusion via regex ______ qstntxt ___

I have the following string:

%pre%

It is a format %code% and is wrong because after the time there is %code% . To catch this snippet I used %code% :

%pre%

How can I remove only the ending considering that I have many occurrences?

    
______ azszpr187418 ___

To capture the microsecond you can use the following regex %code% it says to capture at the end of the string a dot followed by one or more digits followed by a double quotation mark which is a group. In the substitution field, place %code% or %code% is the value of the group catch in the case double quotation.

= > ^ catch in the example:

%pre%

I imagine it is captured to be replaced by something else.

    
______ azszpr187509 ___

In sublime: select exp.regulates and:

%pre%

On-line command:

%pre%     
______ azszpr187513 ___

Using sed looks like this:

%pre%

Adapted from @rray

response     
___

1

I have the following string:

2014-10-12 17:04:29.996

It is a format timestamp and is wrong because after the time there is .996 . To catch this snippet I used regex :

\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{2,3}

How can I remove only the ending considering that I have many occurrences?

    
asked by anonymous 02.03.2017 / 15:59

3 answers

3

To capture the microsecond you can use the following regex \.\d+(")$ it says to capture at the end of the string a dot followed by one or more digits followed by a double quotation mark which is a group. In the substitution field, place or $1 is the value of the group catch in the case double quotation.

= > ^ catch in the example:

DT_HR_ALTERACAO="2015-02-05 10:55:01.324"
                                    ^^^^^  

I imagine it is captured to be replaced by something else.

    
02.03.2017 / 16:03
2

In sublime: select exp.regulates and:

find=    (DT_HR_ALTERACAO="\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\.\d{2,3}
replace= 

On-line command:

perl -i.bak -pe 's/...find anterior.../$1/g' ex.xml
    
02.03.2017 / 20:29
2

Using sed looks like this:

sed -r 's/\.[0-9]{3}"$//' nome-arquivo >> novo-arquivo

Adapted from @rray

response     
02.03.2017 / 20:42