Agregar un carácter al final de la línea para una coincidencia

I have a bunch of files with lines like 'cycles=1000', 'cycles=1500' and so on (the number after the = varies from file to file).

My requirement is: I need to add a trailing zero only in these lines of the file.

There are other lines in the file that I want left untouched.

puede alguien ayudarme con esto?

-Giri

preguntado el 08 de noviembre de 11 a las 09:11

What system (Windows/Linux/other)? -

What programming language are you using? What have you tried so far? Your question is not answerable as it is right now. You need to edit it and be more specific. -

2 Respuestas

Try to use sed command:

cat file.txt | sed 's/cycles=[0-9]*/&0/g'

EDIT: If needed, you can add those line begin and end matching stuff to the command:

cat koe.txt | sed 's/^cycles=[0-9]*$/&0/g'

respondido 08 nov., 11:15

Assuming you're on an environment with decent text processing tools (like UNIX, Linux or Windows with CygWin), you can use awk to do this, as per the following transcript:

pax$ echo 'cycles=1000
notcycles=25
cycles=1500
something else again' | awk '/^cycles=/ {$0 = $0 "0"} {print}'

cycles=10000
notcycles=25
cycles=15000
something else again

Basically, any lines that start with the text cycles= tiene un 0 appended to them.

Then the line (modified or not) is output.

respondido 08 nov., 11:13

Sorry for the vague info. I am in linux ( suse ) and can use awk. I will try this and let u know - giri_lp

@user976474, I've updated the tags to make your question more targetd. - paxdiablo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.