[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] comando sed



On Thu, Nov 09, 2006 at 05:29:56PM -0600, Luis Rodrigo Gallardo Cruz wrote:
> On Thu, Nov 09, 2006 at 08:06:05PM -0300, andmarti@gmail.com wrote:
> > Gente, cómo va? Les tengo una preguntita sencilla:
> > 
> > Tengo en un archivo una línea con "AllowUsers usuario1 usuario2.."
> > Estaba buscando mediante sed agregar texto en la línea.
> > Sé como agregar una linea antes y después pero no EN la línea.
> > 
> > No obstante, lo logro hacer con lo siguiente:
> > 
> > LINEA_OR=`cat archivo |grep AllowUsers`
> > LINEA_NUEVA=`echo $LINEA_OR usuario_nuevo`
> > sed -e "/^AllowUsers/c$LINEA_NUEVA" archivo > archivo2
> > #SI DIRECCIONO AL MISMO ARCHIVO EN LA LINEA ANTERIOR NO FUNCIONA. ME DEJA EL ARCHIVO EN 0 BYTES, asi que:
> > mv archivo2 archivo1
> 
> sed -i "s/^\(AllowUsers.*\)$/\1 y tu texto nuevo/" archivo
> 
> Es decir: sustituye 'toda la linea que empieza por AllowUsers' por 'lo
> que había' mas el texto nuevo. Haz los cambios sobre el mismo archivo (-i).
> 
> 
Muchas gracias.
A vos tambien Santiago, le echaré un vistazo en breve.
Saludos.
-- 
Andrés Martinelli



Reply to: