[opensuse] BASH - easiest way to edit/change a single line in multiple files
Listmates, I haven't been able to find an easy way to make edits to multiple files from the command line without doing: (sed or tr) -> tmpfile -> mv tmpfile original file. What I'm looking for is a fast way to for is a fast way to edit an existing file directly and change one or two parameter. An example would be to edit all files in /etc/zypp/repo.d and change the keeppackages=0 to keeppackages=1 or something similar without having to use the copy and move, or having to edit the files one by one. Is there a way to do it? -- David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung Rankin Law Firm, PLLC | Countdown for openSuSE 11.1 www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday 09 December 2008 09:18:26 David C. Rankin wrote:
Listmates,
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
What I'm looking for is a fast way to for is a fast way to edit an existing file directly and change one or two parameter. An example would be to edit all files in /etc/zypp/repo.d and change the keeppackages=0 to keeppackages=1 or something similar without having to use the copy and move, or having to edit the files one by one. Is there a way to do it?
-- David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung Rankin Law Firm, PLLC | Countdown for openSuSE 11.1 www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small
sed has a switch for editing files in place: sed -i -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* David C. Rankin
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
What I'm looking for is a fast way to for is a fast way to edit an existing file directly and change one or two parameter. An example would be to edit all files in /etc/zypp/repo.d and change the keeppackages=0 to keeppackages=1 or something similar without having to use the copy and move, or having to edit the files one by one. Is there a way to do it?
sed -i will edit the file infile directly without the need of tmpfiles, would that be good enough? -- Mads Martin Joergensen, http://mmj.dk "Why make things difficult, when it is possible to make them cryptic and totally illogical, with just a little bit more effort?" -- A. P. J. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi,
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
There is a perl prog called "treesed" written by Rick Jansen in 1996 that is very handy for this sort of thing. I should think its still lurking out there somewhere. Regards, Tony.. -- Tony Yates Computer Centre, Brunel University, Uxbridge UB8 3PH Assistant Director ------------------------------------------------------------------------ -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Tony Yates wrote:
Hi,
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
There is a perl prog called "treesed" written by Rick Jansen in 1996 that is very handy for this sort of thing. I should think its still lurking out there somewhere.
Regards,
Tony..
Thanks Bogdan, Mads and Tony! I guess I spent so much time focusing on learning the regex aspect of sed that I completely overlooked the -i option. The -i option is great. Tony thanks for the heads-up on treesed. It is a great example script for many aspects of peal. For those interested, the current link for treesed is: http://www.sfr-fresh.com/unix/misc/treesed -- David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung Rankin Law Firm, PLLC | Countdown for openSuSE 11.1 www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Tue, 09 Dec 2008, David C. Rankin wrote:
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
What I'm looking for is a fast way to for is a fast way to edit an existing file directly and change one or two parameter. An example would be to edit all files in /etc/zypp/repo.d and change the keeppackages=0 to keeppackages=1 or something similar without having to use the copy and move, or having to edit the files one by one. Is there a way to do it?
perl -p -i -e 's/keeppackages=0/keeppackages=1/' FILENAMES You can get backups, by specifying an extension after '-i' (see perldoc perlrun for details). -dnh -- Sigmentation fault. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David Haller wrote:
Hello,
On Tue, 09 Dec 2008, David C. Rankin wrote:
I haven't been able to find an easy way to make edits to multiple files from the command line without doing:
(sed or tr) -> tmpfile -> mv tmpfile original file.
What I'm looking for is a fast way to for is a fast way to edit an existing file directly and change one or two parameter. An example would be to edit all files in /etc/zypp/repo.d and change the keeppackages=0 to keeppackages=1 or something similar without having to use the copy and move, or having to edit the files one by one. Is there a way to do it?
perl -p -i -e 's/keeppackages=0/keeppackages=1/' FILENAMES
You can get backups, by specifying an extension after '-i' (see perldoc perlrun for details).
-dnh
Just getting back after my website building sabbatical. Dave this is just what I needed! On ll.1: perl -p -i -e 's/keeppackages=0/keeppackages=1/' s* perl -p -i -e 's/keeppackages=0/keeppackages=1/' [c-q]* perl -p -i -e 's/keeppackages=0/keeppackages=1/' X11\:XGL.repo perl -p -i -e 's/keeppackages=0/keeppackages=1/' repo_* perl -p -i -e 's/keeppackages=0/keeppackages=1/' repo-update.repo [03:01 arete/etc/zypp/repos.d] # grep keeppackages * cc++.repo:keeppackages=1 gcc.repo:keeppackages=1 openSUSE 11.1-0.repo:keeppackages=1 openSUSE_11.1.repo:keeppackages=1 qt44.repo:keeppackages=1 repo_10.repo:keeppackages=1 repo_1.repo:keeppackages=1 repo_2.repo:keeppackages=1 repo_3.repo:keeppackages=1 repo_4.repo:keeppackages=1 repo_5.repo:keeppackages=1 repo_6.repo:keeppackages=1 repo_7.repo:keeppackages=1 repo_8.repo:keeppackages=1 repo_9.repo:keeppackages=1 repo-debug.repo:keeppackages=0 repo-non-oss.repo:keeppackages=0 repo-oss.repo:keeppackages=0 repo.repo:keeppackages=0 repo-source.repo:keeppackages=0 repo-update.repo:keeppackages=0 samba.repo:keeppackages=1 sbrabec.repo:keeppackages=1 X11:XGL.repo:keeppackages=1 Done! Wohoo... -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Bogdan Cristea
-
David C. Rankin
-
David Haller
-
Mads Martin Joergensen
-
Tony Yates