Afficher un message
Vieux 23/08/2006, 20h12   #3
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: process multiple files

On 2006-08-23, Randy wrote:
> I am new to unix shell.
>
> I need to add a single line to the beginning of multiple ( 100's )
> files. Can I automate this through shell scripting and if so, can
> anyone point me to a newbie resource.


line="Inserted line"
for file in ./* ## replace * with whatever pattern you want
do
{
printf "%s\n" "$line"
cat "$file"
} > tempfile && mv tempfile "$file"
done

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
 
Page generated in 0,05513 seconds with 9 queries