On Tue, Nov 13, 2007 at 05:06:23PM -0500, Chris Arnold wrote:
So now i have a need to insert ' at the beginning of text and at the
end in over 2000 files. The text is always the same and is always found on the first line
of the files (there are over 2000 files). The text is
../../wp-blog-header.php and the finished text should look like
'../../wp-blog-header.php'. How would i make a bash script to
accomplish this or is it possible?
For 2000 files the limit of the `*' expansion could be reached.
Therefore you may use `find' together with a shell loop and
the `ed' ... e.g.
find / -name '*.php' | \
while read php; do
ed $php &> /dev/null <<-EOF
1
,s/.*/'&'/
.
w
q
EOF
# ^^^ this is a <TAB>!
done
if you want to use shell special signs literal like `$' in
your text you may use `"EOF"' instead of `EOF'. Please
note that if you're using a `-' before the `EOF' or before
`"EOF"' you are able to indent the second `EOF'/`"EOF"' with
a tabulator sign. If the `-' is missed the `EOF'/`"EOF"' has
to be placed at the very first beginning of the line.
An other editor is the sed, with its inplace option `-i':
find / -name '*.php' | \
while read php; do
sed -ri "1,1 s/.*/'&'/" $php
done
it is a bit shorter ... but ed is in some cases more
powerfull. Nevertheless both editors allow to use
other boundary characters as the `/' ... sometimes
I use `s@old@new@' or `s!old!new!'.
Werner
--
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr
--
To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse+help@opensuse.org