Sed search replace pattern (bash) -


here sample text i'm using sed (in bash, centos). i've broken text lines make easier read. but text below on 1 line.

some text (abc_3.7|autodetect|"}{\fldrslt \plain \f2\fs20\cf2 3:7}}\plain \f2\fs20

xyz_3.16|autodetect|"}{\fldrslt \plain \f2\fs20\cf2 16}}\plain \f2\fs20 more text,

qr_3.11|autodetect|"}{\fldrslt \plain \f2\fs20\cf2 11}}\plain \f2\fs20 something

i want strip each entry: |autodetect|"}{\fldrslt \plain \f2\fs20\cf2 3:7}}

the text between \plain , }} vary, need select everything.

here's code i'm using now:

s/|autodetect|\"}{\\fldrslt \\plain .*}}/ /g; 

the problem. expect results be:

abc_3.7 \plain \f2\fs20 xyz_3.16 \plain \f2\fs20 more text, qr_3.11 \plain \f2\fs20 

but actual results are:

abc_3.7 \plain \f2\fs20 

the .* greedy , matches first data after 'plain' last pair of close braces, including other auto-detects etc. need more refined (less greedy) pattern:

sed 's/|autodetect|"}{\\fldrslt \\plain [^}]*}}/ /g' "$@" 

the '[^}]*' part matches arbitrary sequence of except '}' (and newline).


if script needs go in file, sed script file contains:

s/|autodetect|"}{\\fldrslt \\plain [^}]*}}/ /g 

and invocation becomes:

sed -f sed.script "$@" 

basically, except single quotes go script file. 1 of advantages of using single quotes there less worry escapes. run problems when script has contain single quotes.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -