Re: [SLUG] search and replace multiple files?
* Nick Andrew [2011-08-02 15:44:02 +1000]: > If it's a problem with leaving the editor open with only changed files, > then I can suggest something like this: > > vim -o $(git status --porcelain | awk ' /^ M/ { print $2 } ') * Erik de Castro Lopo [2011-08-02 18:07:11 +1000]: > Assuming that you are keeping this in git, why not just do the > following: > > a) Make sure everything has been commited. > > b) Use sed/perl/python/whatever to do the changes on the command > line. > > c) Use git with an external graphical diff program to review the > changes. Thanks guys for your suggestions! I like the idea of combining sed/git/vim: git commit -m "cleanup" sed 's/foo/bar' * vi `git st -s | grep '^ M' | cut -c4-` # edit changed files Eric, I'll also check out mgdiff. -- Sonia Hamilton http://soniahamilton.wordpress.com http://www.linkedin.com/in/soniahamilton signature.asc Description: Digital signature -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
Sonia Hamilton wrote: > I'm looking for a GUI that allows me to search and replace in multiple > files, then leaves open the files that have changed - any pointers? > > For example, I want to replace "def fubar" with "def snafu" across 50 > files. I then want to close all the files that didn't have changes, so I > can investigate the changed files in more detail (yes, I'm refactoring). > > PS I know about sed, and how to edit multiple files in vim [1]. Assuming that you are keeping this in git, why not just do the following: a) Make sure everything has been commited. b) Use sed/perl/python/whatever to do the changes on the command line. c) Use git with an external graphical diff program to review the changes. For a graphical diff I use mgdiff (in Debian and Ubuntu at least) and have two aliases: alias git-mgdiff='git diff ' alias git-diff='git diff --no-ext-diff ' The external diff is set up in $HOME/.gitconfig using: [diff] external = /home/user/scripts/git-mgdiff-wrapper.sh and the wrapper script is simply: #!/bin/bash mgdiff "$5" "$2" exit 0 HTH, Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
Sonia Hamilton wrote: I'm looking for a GUI that allows me to search and replace in multiple files, then leaves open the files that have changed - any pointers? I regularly open multiple files with the default text editor on Ubuntu (which is http://www.gedit.org). If I close the app, I think, though can't guarantee this, it closes the files I haven't changed and asks me whether I want to save the rest. It may also preserve parameters of the replace command across files that are open at any time. Is that the kind of thing you are looking for? For example, I want to replace "def fubar" with "def snafu" across 50 files. I then want to close all the files that didn't have changes, so I can investigate the changed files in more detail (yes, I'm refactoring). PS I know about sed, and how to edit multiple files in vim [1]. [1] (http://blog.stevenocchipinti.com/2011/05/search-and-replace-in-multiple-files.html). -- Sonia. -- Marghanita da Cruz http://ramin.com.au Tel: 0414-869202 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
On Tue, Aug 02, 2011 at 02:24:47PM +1000, Sonia Hamilton wrote: > * Nick Andrew [2011-08-02 12:23:43 +1000]: > > On Tue, Aug 02, 2011 at 10:29:44AM +1000, Sonia Hamilton wrote: > > > For example, I want to replace "def fubar" with "def snafu" across 50 > > > files. > > > > perl -p -i -e 's/def fubar/def snafu/g' * > > I said: "PS I know about sed, and how to edit multiple files in vim > [1]." Supplying a perl recipe therefore isn't very useful. Perhaps I > should've said "ditto for ruby, perl, python, ...". I know you know about sed but I don't know you know how to edit multiple files in-place in a single command in perl. sed is a pain to edit files in-place as it has to write to a temp file and then typically rename that temp file to replace the original file. > > If you are not using SCM (or git in particular), then you should be. > > http://soniahamilton.wordpress.com/tag/git/ Nice site. > Again, not the question I was asking... I don't know how to get your editor to do it and "leave only changed files open". I suppose it's possible using vim macros but it's not something I have spent any time learning. I know you know how to edit multiple files in vim but this is one of the more trivial features of the editor and I don't know that you know anything about vim macros or have any desire to learn what is probably a pretty complicated solution for a problem which can be solved easily with two steps. I would myself have done the refactoring exactly how I showed it, and let git keep track of what files have changed. If it's a problem with leaving the editor open with only changed files, then I can suggest something like this: vim -o $(git status --porcelain | awk ' /^ M/ { print $2 } ') Nick. -- PGP Key ID = 0x418487E7 http://www.nick-andrew.net/ PGP Key fingerprint = B3ED 6894 8E49 1770 C24A 67E3 6266 6EB9 4184 87E7 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
* Nick Andrew [2011-08-02 12:23:43 +1000]: > On Tue, Aug 02, 2011 at 10:29:44AM +1000, Sonia Hamilton wrote: > > For example, I want to replace "def fubar" with "def snafu" across 50 > > files. > > perl -p -i -e 's/def fubar/def snafu/g' * I said: "PS I know about sed, and how to edit multiple files in vim [1]." Supplying a perl recipe therefore isn't very useful. Perhaps I should've said "ditto for ruby, perl, python, ...". > If you are not using SCM (or git in particular), then you should be. http://soniahamilton.wordpress.com/tag/git/ Again, not the question I was asking... -- Sonia Hamilton -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
On Tue, Aug 02, 2011 at 10:29:44AM +1000, Sonia Hamilton wrote: > For example, I want to replace "def fubar" with "def snafu" across 50 > files. perl -p -i -e 's/def fubar/def snafu/g' * > I then want to close all the files that didn't have changes, so I > can investigate the changed files in more detail (yes, I'm refactoring). git diff If you are not using SCM (or git in particular), then you should be. Nick. -- PGP Key ID = 0x418487E7 http://www.nick-andrew.net/ PGP Key fingerprint = B3ED 6894 8E49 1770 C24A 67E3 6266 6EB9 4184 87E7 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] search and replace multiple files?
jEdit will do that - http://www.jedit.org/ It is java based, so you'll need a JRE installed. Menno On 2 August 2011 10:29, Sonia Hamilton wrote: > I'm looking for a GUI that allows me to search and replace in multiple > files, then leaves open the files that have changed - any pointers? > > For example, I want to replace "def fubar" with "def snafu" across 50 > files. I then want to close all the files that didn't have changes, so I > can investigate the changed files in more detail (yes, I'm refactoring). > > PS I know about sed, and how to edit multiple files in vim [1]. > > [1] > ( > http://blog.stevenocchipinti.com/2011/05/search-and-replace-in-multiple-files.html > ). > > -- > Sonia. > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html