Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

regex - How to replace all the blanks within square brackets with an underscore using sed? -


i figured out in order turn [some name] [some_name] need use following expression:

s/\(\[[^ ]*\) /\1_/ 

i.e. create backreference capture starts literal '[' contains number of non space characters, followed space, replaced non space characters followed underscore. don't know yet though how alter expression works underscores within braces e.g. [a few words] [a_few_words].

i sense i'm close, missing chunk of knowledge unlock key making thing work infinite number of times within constraints of first set of []s contained in line (of sql server ddl in case).

any suggestions gratefully received....

there 2 parts trickery needed:

  1. stop replacing when reach close square bracket (but repeatedly on line):

    s/\(\[[^] ]*\) /\1_/g 

    this matches open square bracket, followed 0 or more characters neither blank nor close square bracket. global suffix means pattern applied sequences starting open square bracket followed blank or close square bracket on line. note, too, regex not alter '[single-word] , context' whereas original translate '[single-word]_and context', not object of exercise.

  2. get sed repeat search 1 started. unfortunately, there isn't way that. sed resumes searching after text substituted; , 1 occasion when don't want that. sometimes, can away repeating substitute operation. in case, have repeat every time substitution succeeds, stopping when there no more substitutions.

two of less known operations in sed ':label' , 't' commands. present in 7th edition of unix (circa 1978), though, not new features. first identifies position in script can jumped 'b' (not wanted here) or 't':

[2addr]t [label] 

branch ':' function bearing label if substitutions have been made since recent reading of input line or execution of 't' function. if no label specified, branch end of script.

marvellous: need:

 sed -e ':redo; s/\(\[[^] ]*\) /\1_/g; t redo' data.file 

except - doesn't work on 1 line (at least, not on macos x). did work admirably, though:

sed -e ':redo         s/\(\[[^] ]*\) /\1_/g         t redo' data.file 

or, noted in comments, write 3 separate '-e' options (which works on macos x):

 sed -e ':redo' -e 's/\(\[[^] ]*\) /\1_/g' -e 't redo' data.file 

given data file:

a line [one blank] word inside square brackets. line [two blank] or [three blank] words inside square brackets. line [no-blank] word inside square brackets. line [multiple words in single bracket] inside square brackets. line [multiple words in single bracket] [several times on 1 line] 

the output sed script shown is:

a line [one_blank] word inside square brackets. line [two_blank] or [three_blank] words inside square brackets. line [no-blank] word inside square brackets. line [multiple_words_in_a_single_bracket] inside square brackets. line [multiple_words_in_a_single_bracket] [several_times_on_one_line] 

and, finally, reading fine print in question, if need done in first square-bracketed field on each line, need ensure no open square brackets before 1 starts match. variant works:

sed -e ':redo' -e 's/^\([^]]*\[[^] ]*\) /\1_/' -e 't redo' data.file 

(the 'g' qualifier gone - isn't needed in other variants either given loop; presence might make process marginally more efficient, impossible detect that. pattern anchored start of line (the caret) , contains 0 or more characters not open square bracket before first open square bracket.)

sample output:

a line [two_blank] or [three blank] words inside square brackets. line [no-blank] word inside square brackets. line [multiple_words_in_a_single_bracket] inside square brackets. line [multiple_words_in_a_single_bracket] [several times on 1 line] 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -