Prev: Anyone have Solaris 2.6 Media available (needed for a Sparcbook 3)
Next: GNOME session file documentation?
From: Martin Paul on 16 Jul 2010 03:26 Michael Laajanen wrote: > Chris Ridd wrote: >> Use sed? Personally I prefer using perl with its convenient in-place >> editing flag (-i): >> >> perl -pi -e 's/define SIM 0/define SIM 1/g' * >> > Excellent :) whenever I use sed I always pipe to a new file and then > copy it back to the original name this is much better. Can this be done > with sed aswell? No, I guess that's why sed is called the "stream editor". But you can use "ed" instead to edit files in place. I've used something like that in shell scripts in the past: for f in t.* do ed $f >/dev/null <<EOT ,s/define SIM 0/define SIM 1/ w q EOT done Nowadays, as perl is included by default in most operating systems, I prefer to use that. Martin. -- SysAdmin | Institute of Scientific Computing, University of Vienna PCA | Analyze, download and install patches for Solaris | http://www.par.univie.ac.at/solaris/pca/
From: Sandy Tipper on 18 Jul 2010 10:05 "Martin Paul" <map(a)par.univie.ac.at> wrote in message news:4c4009a4$0$28520$3b214f66(a)usenet.univie.ac.at... > Michael Laajanen wrote: >> Chris Ridd wrote: >>> Use sed? Personally I prefer using perl with its convenient in-place >>> editing flag (-i): >>> >>> perl -pi -e 's/define SIM 0/define SIM 1/g' * >>> >> Excellent :) whenever I use sed I always pipe to a new file and then copy >> it back to the original name this is much better. Can this be done with >> sed aswell? > > No, I guess that's why sed is called the "stream editor". But you can use > "ed" instead to edit files in place. I've used something like that in > shell scripts in the past: > > for f in t.* > do > ed $f >/dev/null <<EOT > ,s/define SIM 0/define SIM 1/ > w > q > EOT > done > > Nowadays, as perl is included by default in most operating systems, I > prefer to use that. > > Martin. > -- > SysAdmin | Institute of Scientific Computing, University of Vienna I usually use 'ex' for that (vi without the full screen mode). But unless you are very careful, be sure to put single quotes around the here-doc tag, to prevent accidental variable substitution ($s in the command looks like a variable): fr f in O do ex $f <<-'EOT' 1,$s/define SIM 0/define SIM 1/ wq EOT done
First
|
Prev
|
Pages: 1 2 Prev: Anyone have Solaris 2.6 Media available (needed for a Sparcbook 3) Next: GNOME session file documentation? |