www.mamboteam.com
www.elsotanillo.net
Home arrow Linux arrow Scripts Bash arrow Linux - Script para modificar multiples ficheros usando un bucle for y sed
jueves, 20 noviembre 2008
 
 
  • Español
  • English
  • Français
Menu Principal
Home
Windows
Linux
Pictures
Blog
Noticias RSS
Enlaces de interes
Frases Celebres
Mi Clave GPG
Cursos LPI de la UOC
Utilidades
Search
Webmail
Diccionarios Online
El tiempo
Alicante, Spain
Temp: 15°C
Wind Chill: 15°C
Humidity: 77%
Speed: 16 km/h
Direct.: 50°
Barom.: 1023.0 mb
NE
Show more details
Provided by: 
Web translation / Traduction web

british flagHi, I am translating some of the articles from Spanish to English. If you are interested in one particular article, drop me a line. Maybe you can help me. :)

Salut, je suis en train de traduire des articles d' Espagnol a Français, si tu veux un article, ecri moi. Peut-être tu peux m' aider. :)

Linux - Script para modificar multiples ficheros usando un bucle for y sed PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Juan Sierra Pons   
domingo, 19 noviembre 2006
Compartelo:
Delicious
Meneame
Mister.Wong
There are no translations available

Algunas veces nos encontramos con que tenemos que hacer la misma modificación en multiples ficheros.

Por ejemplo hemos puesto una ruta mal en todos nuestros ficheros .html y tenemos que hacer la misma modificación en todos. Esto podria significar modificar 10, 100 ficheros.

Veamos como podemos ahorrarnos todo este trabajo.

Para el ejemplo vamos a usar un caso muy simple: en todos los ficheros .html hemos puesto la ruta mal.

En los ficheros .html tenemos:
src=Images/nuevo-flash_15.gif
y tendriamos que tener:
src=images/nuevo-flash_15.gif Es decir la primera "i" de images en minusculas.

El script es el siguiente:


for i in *.html
do sed s/Images/images/g $i > $i.bak
mv $i.bak $i
done

En primer lugar con el bucle for, recorremos todos los ficheros .html y con el comando sed hacemos la modificacion que queremos para cada uno de los ficheros.

El comando sed es una herramienta muy potente ya que nos permite hacer multitud de de operaciones sobre ficheros de forma desatendida, ej: en un script.

Comments
Add NewSearchRSS
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
 
Security Image
Please input the anti-spam code that you can read in the image.

Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved.

Last Updated ( martes, 01 enero 2008 )
 
< Prev   Next >
Frase celebre del día
Visitas
Imagenes
Linux Howtos
Visto en Barrapunto
Barrapunto
Sindícate
 
Top! Top!