| |
| |
| |
|
Comments:
<0> you can use two substitutions, but that might not quite be what you want <1> Do you think this can solve my problem? <0> hmm <0> the bracket nesting makes things interesting <2> hello all <1> goldfish, bearPerson: Thanks for thinking about my problem. <1> wish you a good night. <3> u 2 <0> only thing I could think about is s/\((.*\)patt\(.*)\)/new/
<0> er <0> only thing I could think about is s/\((.*\)patt\(.*)\)/\1new\2/ <1> But the problem is that pattern patt could occur multiple times and so you need the 'g' option but this option would include the \1\2 which occurs only once. <0> *nod* <0> kay, mean trick time <1> Ok, i have to finish to reach my bus. If someone get something like a brainstorm he can send me the idea as email. <1> My address is Vasudva.Martin@gmx.de <0> s/^[^(]*(/&\n/; s/)[^)]*$/\n&/; tloop; :loop; s/\(\n.*\)patt/\1new/; tloop <1> I take a look to your suggestion tomorrow. I saved it in an file. <0> kay <1> bye <0> see you <4> anyway to substitute a multiline string using sed ? Something like sed {/OLD_STRING/"$new_multiline_string"/g} <5> grepper: You forgot the s command. <4> heh, true <5> grepper: s/pattern/line1\ <5> line2\ <4> anyway, it doesn't work <5> line3/ <4> yeah \n works <4> but $new_multiline_string is a var <5> \n only works on GNU sed <5> Well, and others probably. <4> so \n is not helpful <5> Inserting shell variables with arbitrary contents is never a good idea. <4> I did an awk solution that works ok, but was still curious if it could be done with sed <5> s,[%`"\],\\&,g <5> s,\n,\\&,g <4> hm, sorry I don't understand that one, where is the var ? <5> safe_var=$(echo "$unsafe_var" |sed -e 's,[$`"\],\\&,g' -e 's,\n,\\&,g') <5> <input sed -e 's/pattern/'"$safe_var"'/g' >output <5> safe_var=$(echo "$unsafe_var" |sed -e 's,[$`"\],\\&,g' -e 's,\n,\\&,g' -e 's,/,\\&,g') ## oops, forgot the delimiter. <5> er, sorry, that won't work : <5> mksafe() { echo "$1" |sed -e 's,[$`"\/],\\&,g' -e '$!s,$,\\,'; }
<5> <input sed -e 's/pattern/'"$(mksafe "$unsafe_variable")"'/g' >output <5> http://www.rafb.net./paste/results/evZrnc11.html <5> I forgot I wrote that a while back. <4> ok, suppose the input is already in that format ? line1\ line2\ etc ? <5> Well, then you don't need to put \\ at the end of each line. <4> sure, but still need to substitute the multiline var for something <5> Hmm? <4> as I said originally: sed {s/OLD_STRING/"$new_multiline_string"/g} <4> using line1\ it would output it all on one line, no ? <4> it has to stay multiline <5> printf 'foofoo\n' | sed -e 's/foo/1\ <5> 2\ <5> 3/g' <5> It works for me. <5> Unless I'm misunderstanding what you want to do. <4> foo="a <5> printf 'foofoo\n' |sed -e "$(printf 's/foo/1\\\n2\\\n3/g')" <4> multiline string" <4> it works with \n, but not with a literal newline <5> As you have it, it will not work. <4> hm <5> http://www.rafb.net./paste/results/eu7MyE88.html I fixed clean_for_replacement() <5> sed 's/OLD_STRING/'"$(clean_for_replacement "$new_multiline_string" /)"'/g' <4> playing with it, thanks <4> hm, that puts new_multiline_string all on one line <4> I get unterminated `s' command <4> if I don't escape EOL in the input <4> and if I do escape it, it gets put all on one line <4> phebehouse.dyndns.org/tovid/multiline_sub.sh <4> ah, it was the newline after __BUTTONS <4> working now <4> thanks prec <6> can I tell sed to be --line-buffered ? <7> woah! <7> first action int he whole day :) <6> it's -u if someone cared <6> s <7> h :) <7> ah
Return to
#sed or Go to some related
logs:
#sdl defpackage :use is undefined satan-linux apt-get tightvnc damn small linux whath videos about india emerge newroot access denied apt-get ubuntu sphinx2 dapper #sql comamnd lpr -P
gcc-config error: Could not run/locate i386-pc-linux-gnu-gcc
|
|