Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Agregar texto al final de una linea

581 views
Skip to first unread message

speeter

unread,
May 10, 2004, 1:14:44 PM5/10/04
to
Hola a todos

Estoy haciendo un script en bash y necesito añadir un texto al final de
una linea determinada de un archivo.

Alguna idea?

Saludos

Gonzalo Pérez de Olaguer Córdoba

unread,
May 10, 2004, 1:36:06 PM5/10/04
to
El Mon, 10 May 2004 19:14:44 +0200 speeter <spee...@hotmail.com>
escribió:

man sed(1)

sed -e 'IDENTIFICADOR_DE_LINEAs/$/NUEVO_TEXTO/' < in > out

> Saludos
>

--
Gonzalo Pérez de Olaguer Córdoba <gp...@iies.es>
PGP key 2861C704 --- F206 5671 6789 425D 111C 1302 214F 1934 2861 C704

sio2

unread,
May 11, 2004, 8:58:52 AM5/11/04
to
El lunes, 10 de mayo de 2004, a las 17:14 GMT, speeter escribió:
> Hola a todos
>
> Estoy haciendo un script en bash y necesito añadir un texto al final de
> una linea determinada de un archivo.
>

Pues depende de cómo identifiques a la línea. Supongamos este fichero:

#v+
$ cat prueba.txt
Hola
Adios
#v-

Si quieres añadir "-un saludo" a la línea que dice Hola, puedes hacerlo
así:

#v+
ed prueba.txt <<"SCRIPT"
/Hola/s/$/-un saludo/
w
q
SCRIPT
#v-

Y ya está:

#v+
$ cat prueba.txt
Hola-un saludo
Adios
#v-

--
Si quieres que te sigan las mujeres, ponte delante.
--- Francisco de Quevedo ---
Si Dióxido de Silicio | Debian GNU/Linux
/ \ (SiO2) | José Miguel Sánchez Alés
O O Mineral de Cuarzo | sio2....@online.fr | URL #257033

Esteban Navarro

unread,
May 11, 2004, 4:09:38 PM5/11/04
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

speeter wrote:

> Estoy haciendo un script en bash y necesito añadir un texto al final de
> una linea determinada de un archivo.

echo "texto a añadir al final de la linea" >> ~/fichero.txt

- --
Esteban Navarro
Fondos de Escritorio:
http://scandisk.todofondos.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAoTMCoVO1uCntWAwRAhCkAJ9lKeVCFjynJ0JVwOWQESSXxUbRGgCfadpv
Jc/x9FfCeDE5vnmjqUnNktA=
=9h0m
-----END PGP SIGNATURE-----

Jesús M. NAVARRO

unread,
May 11, 2004, 7:36:54 PM5/11/04
to
Hola, Esteban:

Esteban Navarro escribió en es.comp.os.linux.programacion:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> speeter wrote:
>
>> Estoy haciendo un script en bash y necesito añadir un texto al final de
>> una linea determinada de un archivo.
>
> echo "texto a añadir al final de la linea" >> ~/fichero.txt

¿Ya has probado eso que dices? (me da a mí que no).
--
SALUD,
Jesús
***
jesus_...@undominio.net
***

Alberto Giménez

unread,
May 11, 2004, 7:10:07 PM5/11/04
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

El Tue, 11 May 2004 22:09:38 +0200, Esteban Navarro escribió:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> speeter wrote:
>
>> Estoy haciendo un script en bash y necesito añadir un texto al final de
>> una linea determinada de un archivo.
>
> echo "texto a añadir al final de la linea" >> ~/fichero.txt

Jeje, creo que has hecho trampa. Eso te la añade al final del archivo,
no de una línea en concreto.

Para eso está sed(1). Es cojonudo para hacer este tipo de chorradillas.
Saludos

- --
Alberto Giménez, SimManiac en el IRC
http://www.almorranasozial.es.vg
GnuPG ID: 0x3BAABDE1
WinError 01E: Timing error - Please wait. And wait. And wait. And wait.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAoV1P0keCtzuqveERAr91AJsFMV2RnKENmwqFdX7fWFGpO5TRBgCglNoU
fK4695o1wf4jzRnhHiW91CM=
=DSnc
-----END PGP SIGNATURE-----

0 new messages