This could be a job for placeholders: 1. Open the folder with your files in BBEdit (creating an instant-project - or: add all files to the source list of a new project) 2. Mulitfile-replace (in the new project): search for \A (the start of the file), replace with a placeholder, probably #LOCALPATH# 3. Use Markup > Update > Folder to fill the placeholders with meaning.
This should write the path at the top of each file. I can’t test this at the moment, but it should work. In any case please try this on a copy of files first. Regards, Roland On Thu, May 18, 2017 at 11:57 AM, Geoff Hicks <[email protected]> wrote: > Well, life unexpectedly intruded on my investigation of this matter, but > needing the challenge of re-acquiring knowledge which I used to have at my > fingertips decades ago, I have done the necessary due diligence and trawled > the man pages and web and found a satisfactory solution which I thought > should be shared here. > > As I had already determined, BBEdit does not have access to file system > variables during multi-file replacement operations from within the app. > From seeing all the AppleScript related postings, I had assumed that this > would be where I would need to research, and felt daunted by the task of > acquiring sufficient knowledge to get to the point of even testing a > solution. > Having been a un*x admin in another life, I felt that I would have quicker > success with command-line tools like sed and awk, so I thought I'd start > there. > > Before even getting to step one, I ran into another issue in my first > terminal session: traversing macOS style folder aliases in the shell! > After much binding in the marsh, it transpired that my long preferred tcsh > shell was not going to cut the mustard without escaping backslashitis, so I > would have to go with bash to be able to use function aliases and overload > the builtin cd command to traverse finder aliases as it already does for > symlinks. > > See https://apple.stackexchange.com/questions/180762/how-to- > go-to-alias-from-terminal > > Once that hurdle was overcome, and I could at least traverse the folder > tree to a place where I could test my filename insertion into the relevant > text files, I ran into my next faulty assumption. > I had frequently used find as a sysadmin to perform selective backups and > data transfers, but within the current directory, 'find . -type f -name > "*.ext" -print' continued to give me a pesky preceding ./ on all the > filenames, when what I needed the full, absolute path of each file to be > inserted into it. > Research seemed to imply that I could define a shell function abspath() to > make the conversion, when I stumbled on one of the later answers on the > following page: > > http://stackoverflow.com/questions/3915040/bash-fish- > command-to-print-absolute-path-to-a-file > > which points out that supplying an absolute path to find 'find $(pwd)', > using the output of the shell command pwd (present working directory), > gives absolute paths in the output, whereas 'find .' will always give > relative paths, so an abspath function was redundant! > Great! Absolute paths to required files sorted. Next! > > The stream editor sed, which I had thought to use for substitution (with > the -E extended grep repertoire) was stubbornly line buffered, and the vast > majority of the replacements I needed to make had patterns with multiple > newlines, which it failed to match. > > So, it's off to Perl land we go... and... huzzah! For best success, use a > sewage pump! > > #!/bin/bash > find "$PWD" -type f -name "*.cm2" -exec perl -0pi -e > 's|(\t\t\t\}\n\t\t\}\n)(\tcameraModel)|\1\tcustomData\n\t\t\{\n\t\tdata > PoseName 1 0 "$ARGV"\n\t\t\}\n\2|' "{}" \; > > The single-line shell command above is what I have come up with. > After traversing to the appropriate parent folder of all the files which > need to be changed using cd (change directory), > find will search the folder defined by the output of the builtin shell pwd > command (which must be delimited with double-quotes as the folder names > contain spaces), > for files ( -type f ) with names ending with .cm2 (again delimited as they > will contain spaces) ( -name "*.cm2" ) > each file found will have its absolute path passed to perl, both as the > name of the file to be operated upon ( double-quote delimited "{}" ) and as > $ARGV, a shell-variable argument component of the replacement string. > The perl command parameters tell perl to use a null character for > buffering (equivalent to End Of File) rather than newlines and perform an > inline replacement of the original file without backup (I have time machine > backups) > Gratifyingly, the string substitution is formatted exactly as it would be > in BBEdit, so I can test the search and replacements in-app before directly > copying them into the script from the find dialog. > > The script turns directories of files containing unique blocks like: > > } > } > cameraModel poser > > into: > > } > } > customData > { > data PoseName 1 0 "/Volumes/HiggsBosonHD/Users/... > .../Runtime/libraries/Camera/Face/CloseUp 51mm f16.cm2" > } > cameraModel poser > > with each file containing its own absolute path reference. > > -- > This is the BBEdit Talk public discussion group. If you have a > feature request or would like to report a problem, please email > "[email protected]" rather than posting to the group. > Follow @bbedit on Twitter: <http://www.twitter.com/bbedit> > --- > You received this message because you are subscribed to the Google Groups > "BBEdit Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/bbedit. > -- This is the BBEdit Talk public discussion group. If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/bbedit.
