>From Peter N Lewis on 3/6/06 6:19 am: >> Can I do a 'sort lines...' based on how many times a particular character >> appears in the line? > > Not directly. > > I suggest you first translate the file to start with <count of > commas><tab>, then sort numerically, then remote the leading count. > > Adding the count of the number of commands after the last \ is done > with perl like this: > > perl -i.bak -n -e 'm/.*\\(.*)/; print $1 =~ tr/,/,/, "\t", $_;' file.txt >
Thanks Peter - this works perfectly from Terminal, and if the file is open in BBEdit I see the results in the open document. What would I have to do to make this into a filter that I can call from the #! menu in BBEdit? I'd like it to work on the front document, whatever it was called (using it from the Terminal, the file must be called file.txt) > Broken down, it means: > > -i - read and then write that input file > -i.bak - saving a backup copy with extension .bak > -n reading each line but not printing anything > -e with script that follows > m/.*\\(.*)/ find everything after the last \ > print print the following > $1 =~ tr/,/,/ - translate in $1 every comma to a comma, returning the number > "\t" tab > $_ the line, including trailing linefeed (make sure your file is > linefeed line endings) > file.txt the name of the input/output file Thanks for the explanation - I roughly understand, but this is a bit like entering a cavern with a candle. It's exposed how much I don¹t know. Are $1 and $_ special strings? > Then sort numerically (sort -n or use BBEdit) > Then remove the leading <number><tab> (left as an exercise). I can do this bit: Replace all with Find "^.*\t" replace "" (nothing) Cheers Rich -- ------------------------------------------------------------------ Have a feature request? Not sure the software's working correctly? If so, please send mail to <[EMAIL PROTECTED]>, not to the list. List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml> List archives: <http://www.listsearch.com/BBEditTalk.lasso> To unsubscribe, send mail to: <[EMAIL PROTECTED]>
