Extract BBEdit search history into a shell script - regex
I live off the regex search/replace in BBEdit.
At times I cycle through a history of 8-9 search/replaces to convert a file.
Is there anyway to extract the BBEdit search/replace history?
Best would be to just have the history auto generate a shell script.
I realise I can copy them by hand, but by the time I realise I need it; I'm up to 7-9 rather complex regex blots that would just be annoying to hand copy and paste.
Any ideas warmly welcomed.
Found what I should have looked for from the beginning.
com.barebones.bbedit.plist has an array entry
FindDialog:SearchReplaceHistory
This entry is an array of dicts that includes all settings for the search/replace.
A simple tool can be spun to pull the data and convert in on the fly to a shell script.
Related
Trying to eliminate second regex exec
I am wondering if there is a way to declare boundaries other start of line or end of line but based on a value in the text. I am trying to optimize my code and right now I find a section in my doc and extract it based on a regular expression. Then I run that extracted section through another expression. For simplicity my text looks like the <start><doc><font>123</font></doc><doc><font>234</font></doc><doc><font>345</font></doc><doc><font>456</font></doc><end> Since my <start> is not the start but somewhere in doc I have to find that. I assume if its possible it should be more effective then running two expr exec's to get the data. Anything small will help as my script will have to run at least one million times.
Not really sure about the efficiency, if your data would be as simple and clean as it is printed in the question, this expression might be an start: (<start>(<doc>(<font>.*?<\/font>)<\/doc>)<end>) Otherwise, you might want to clean your data first, and maybe find some alternative solutions. DEMO
Copy File with Regex Replacement
I'm trying to find a simple/elegant command-line solution for a process that is often used in scripts. Something like: (Fictional example) CopyWithReplace <SourceFile> <DestFile> -m <match regular expression> -r <replacement regular expression> It would copy the text file with the matched text replaced as specified. Ideally, the find/replace would happen in the pipeline, rather than as a secondary step. (Destinations quite often are remote locations, and long distance WAN links are often not as fast and reliable as desired.) What would be the simplest** way to achieve this scriptable functionality in a windows environment? ** Simplest = easy to write batch code, fewest 3rd party tools, etc. Bonus points for a reasonably standard Regex implementation.
This can be achieved with sed. The basic usage pattern, for a substitution as you described, is: sed 's/regexp/replacement/g' inputFileName > outputFileName sed is a Unix utility, but there are several ways of using it in Windows if you wish. This StackOverflow post lists the various options available.
Search/replace in block selection in Notepad++
Is there a way to limit search/replace only to a columnar block selection in Notepad++? Here is what I am trying to do: I am bulk-editing metadata extracted from large numbers of photos. The metadata comes to me as a csv file with no quotes around fields in header line and no quotes around first field in each succeeding line. I edit this file in Open Office calc which exports with quotes around all fields. I can easily edit header row but the problem comes in stripping quotes from only first field in successive lines. I can use notepad in columnar mode but, after selecting the first column, the 'search only in selection' option box is greyed out. I can do this by hand but it means lots of hand-work and increased chance of error.
I know, this probably won't help you any more, but I just had the same problem and stumbled across this question. I found moving the block in question to a new file and performing the find/replace there works quite decently. When moving the block back, be sure to select it in block mode (see this question).
No. Another editor may have this feature.
sort of a late reply but... I had the same problem when I moved to a new machine with Notepad++ installed. Previously, I was using a text editor called Boxer that had this feature, which I found invaluable. Its not free-ware however.
You may not be able to Search/Replace within a columnar selection, but you can easily carry out your task within Notepad++. Use Find and Replace feature, with the Regular Expressions box checked. If you want to remove quotes only from a target column, use the following regular expression in the Find field: (^([^,]*,){i})"([^,\n\r]*)"(.*$) Replace i with the position of the target column minus 1. (i.e.- Us 2 if you want quotes around the third column, 0 for the first column, etc) In the Replace field use: \1\3\4 Clicking "Replace All" will strip quotes from the target column. If you want to blow away all quotes surrounding each element in your csv without prejudice, use the following regular expression in the Find field: ((?<=,)|(?<=^))"(.*?)"((?=$|,)) In the Replace field use: \1\2\3 Clicking Replace All will strip quotes form the columns. Example Since you didn't provide an example csv file, I'll walk through my own working example. Below is my csv: "0","1","2","3","4","5","6","7","8","9" "10","11","12","13","14","15","16","17","18","19" "20","21","22","23","24","25","26","27","28","29" "30","31","32","33","34","35","36","37","38","39" "40","41","42","43","44","45","46","47","48","49" "50","51","52","53","54","55","56","57","58","59" "60","61","62","63","64","65","66","67","68","69" "70","71","72","73","74","75","76","77","78","79" "80","81","82","83","84","85","86","87","88","89" "90","91","92","93","94","95","96","97","98","99" "100","101","102","103","104","105","106","107","108","109" "110","111","112","113","114","115","116","117","118","119" "120","121","122","123","124","125","126","127","128","129" "130","131","132","133","134","135","136","137","138","139" "140","141","142","143","144","145","146","147","148","149" "150","151","152","153","154","155","156","157","158","159" "160","161","162","163","164","165","166","167","168","169" "170","171","172","173","174","175","176","177","178","179" "180","181","182","183","184","185","186","187","188","189" "190","191","192","193","194","195","196","197","198","199" If I wanted to remove quotes from the second column, I would use the below Find and Replace fields (^([^,]*,){1})"([^,\n\r]*)"(.*$) \1"\3"\4 Clicking Replace All yields the below result: "0",1,"2","3","4","5","6","7","8","9" "10",11,"12","13","14","15","16","17","18","19" "20",21,"22","23","24","25","26","27","28","29" "30",31,"32","33","34","35","36","37","38","39" "40",41,"42","43","44","45","46","47","48","49" "50",51,"52","53","54","55","56","57","58","59" "60",61,"62","63","64","65","66","67","68","69" "70",71,"72","73","74","75","76","77","78","79" "80",81,"82","83","84","85","86","87","88","89" "90",91,"92","93","94","95","96","97","98","99" "100",101,"102","103","104","105","106","107","108","109" "110",111,"112","113","114","115","116","117","118","119" "120",121,"122","123","124","125","126","127","128","129" "130",131,"132","133","134","135","136","137","138","139" "140",141,"142","143","144","145","146","147","148","149" "150",151,"152","153","154","155","156","157","158","159" "160",161,"162","163","164","165","166","167","168","169" "170",171,"172","173","174","175","176","177","178","179" "180",181,"182","183","184","185","186","187","188","189" "190",191,"192","193","194","195","196","197","198","199"
My search on internet, to to see weather notepad++ suports this; brought me here. I have used TextPad and confirm that it supports find-and-replace within column selected block. Also TextPad is free for personal use.
how to do vi search and replace within a range in sublime text
I enabled vintage mode on sublime text.. but there are some important vim commands that are lacking.. so let's say I want to do a search and replace like so :10,25s/searchedText/toReplaceText/gc so I wanna search searchedText and replace it with toReplaceText from lines 10 to 25 and be prompted every time (ie yes/no).. how do I do this with Sublime Text? everytime I hit : it gives me this funny menu.. any way around that?
If you so much would like to see vim in action, try the other way around; ie enable sublime stuff in vim. Here are 2 links that might come in handy: subvim and vim multiple cursors (Which is one amazing feature in sublime that lacks in native vim). Hope that gets you creative ;)
Unfortunately vintage mode does not understand ranges. The best way I know how to do this is with incremental search: highlight the first occurrence of searchedText on line 10 hit cmnd/ctrl D to have Sublime find the next occurence If you you want the next occurrence ignored, hit cmnd/ctrl K Once you have highlighted all the occurrences, you can replace them all at once, as Sublime has left cursors behind on every occurrence you opted in on.
VintageEx gives you a Vim-like command-line where you can at least perform substitutions. Well, that's how far I went when trying it. I don't know how extended the subset of Vim commands it implements is but I'd guess that it's not as large as the original and, like with Vintage, probably different and unsettling enough to keep a relatively experienced Vimmer out. Anyway, I just tried it again and indeed you can more or less do the kind of substitution you are looking for, which instantly makes ST a lot more useful: :3,5s/foo/bar/g :.,5s/bar/foo/g :,5/foo/bar/g :,+5/bar/foo/g Unfortunately, it doesn't support the /c flag.
a plugin named vintageous offers more features including search function. It's available in package control
although this question is answered.. i figured this would add some value the full functionality of vi search/replace is possible with the ruby mine IDE, once you install the ideavim plugin. The idea is perfect for ruby on rails by the way.
notepad++ regular expressions to convert lines for SPSS syntax editor
I am curently busy with bulding a synthax document in SPSS and have a column of variable strings that consists of approximately 40 lines (it will be much much more in coming week). SPSS has a nice way of creating it (can be seen here :) http://vault.hanover.edu/~altermattw/methods/stats/reliable/reliability-1.html) but it can be done per one variable at a time which is possible to automatize. I am a total beginner (I wouldn't mind if you would call me n00b) at search&replace with reqular expressions in notepad++ but I can use the extended search function as a basic user :P The data contains scores Likert scale (from 1-7) and I would like to reverse it to do some tests. For example: my variable name on the line is q_4_SQ001 and the sline in synthax editor is q_4_SQ001=COMPUTE q_4_SQ001r=8-q_4_SQ001. My question so far is thus: How can I convert a line containing a unique variable name into it's revers formula? So in this case, how can I replace the following lines: q_4_SQ001 q_4_SQ002 q_4_SQ003 q_4_SQ004 into the synthax given under: COMPUTE q_4_SQ001r=8-q_4_SQ001. COMPUTE q_4_SQ002r=8-q_4_SQ002. COMPUTE q_4_SQ003r=8-q_4_SQ003. COMPUTE q_4_SQ004r=8-q_4_SQ004. Please remark the dots in the end of each line I did this manually to give you an impression of what I would like to achieve. My data set has different questions and different variable strings so I would like to make my life a bit easier right now :P I also tried recording and running a macro as stated in here (http://stackoverflow.com/questions/2467875/notepad-replace-all-regular-expression-start-of-the-line-and-end-of-the-line) but that still is pretty time consuming since I have to do each line manulally and clean up with extended search in the end. Wouldn't it be easier to convert each line? Thanks a bunch in advance :)
Funny, Notepad++ works under Wine, as I just found out ;) New file, inserted: q_4_SQ001 q_4_SQ002 q_4_SQ003 q_4_SQ004 Select all (CTRL+A), replace (CTRL+R). Tick Regular Expr, stick ^(.*)$ in the "find" bit (first textbox), and COMPUTE \1r=8-\1. in the "replace" bit (second textbox). Hit the Find button, and then the Replace Rest button. Parenthesis () around a pattern cause the pattern to be "memorised", each set of parenthesis available to the replacement pattern via \1, \2, etc. After the replace, I got: COMPUTE q_4_SQ001r=8-q_4_SQ001. COMPUTE q_4_SQ002r=8-q_4_SQ002. COMPUTE q_4_SQ003r=8-q_4_SQ003. COMPUTE q_4_SQ004r=8-q_4_SQ004. Which I assume is what you wanted. Enjoy.