In GNU / Linux there are many tools that are already pre-installed with the system and that not everyone uses. Some of them are certainly unknown, instead, they could do many things to facilitate our daily work. Today I present you to the command thirst, it is not a rare utility, in fact it is well known. But maybe you did not know everything that this can do flow editor (hence its name Stream EDitor). A powerful legacy Unix program.
sed can accept a file as input, it will read it and will modify line by line according to the order given. The result will be shown by the standard output, that is, by the screen in this case. Thus it allows to manipulate data flows to find, cut, insert or replace lines of text using regular expressions. Maybe some features remind you of other tools like ed or ex.
But for you to understand better, here are some good practical examples of using sed. I have left them commented so that you know what each one is for and group them all within the same box:
#Ver las lÃneas de un fichero de texto de la 15 a la 17 sed -n 15,17p nombre.txt #Mostrar todo el contenido excepto las lÃneas 10 a 14 sed 10,14d nombre.txt #Mostrar cada 3º lÃnea comenzando desde la 2 sed -n '2,3p' nombre.txt #Eliminar la lÃnea 4 sed 4d nombre.txt #Eliminar la última lÃnea, sea cual sea sed $ d nombre.txt #Eliminar un rango de lÃneas sed '20 -34d ' nombre.txt #Eliminar solo las lineas mencionadas sed '29 -34! d ' nombre.txt #Agregar una lÃnea en blanco tras cada lÃnea de texto sed G nombre.txt #Localizar "hola" y sustituirlo por "hello" sed 's / hola / hello /' nombre.txt #Sustituir palabra de una lÃnea concreta sed '4 s / peligro / seguridad /' nombre.txt #Sustituir una lÃnea donde se encuentre la palabra "adios" por otra lÃnea escrita sed '/ adios / c "Esta será la nueva lÃnea"' nombre.txt
I hope I have helped you with this sed minitutorial...