linux - parrafos - como insertar texto en una pagina web en html
Cómo extraer texto entre etiquetas HTML con o condición varias veces (1)
He estado investigando cómo extraer etiquetas de título de html. Casi me he dado cuenta de que Regex y html no se mezclan y que grep se puede usar. Sin embargo, el código que encontré aquí , se ve así:
awk -vRS="</title>" ''/<title>/{gsub(/.*<title>|/n+/,"");print;exit}''
Ahora, esto funciona para encontrar el texto entre las etiquetas de título solo una vez. Me gustaría saber cómo puedo hacerlo funcionar en cada línea. Podría hacer un cat file; while read line; do ...; done cat file; while read line; do ...; done cat file; while read line; do ...; done . Sin embargo, sé que probablemente no sea muy eficiente y hay una mejor manera.
En segundo lugar, en el archivo necesito mantener las líneas que comienzan con la cadena ''-''. Creo que esto requiere agregar una declaración ''o'' en awk para que coincida con las etiquetas de título y cualquier línea que comience con ''-''
El archivo de entrada se vería así:
text text text <title>random text of the title 1</title> random html stuff
--time--
xyz more random text <title>random text of the title 2</title> hmtl text
--time--
some text <title>random text of the title 3</title> more text tags
--time--
text here <title>random text of the title 4</title> random text html
--time--
El resultado deseado:
<title>random text of the title 1</title>
--time--
<title>random text of the title 2</title>
--time--
<title>random text of the title 3</title>
--time--
<title>random text of the title 4</title>
--time--
No soy tan bueno con awk, pero estoy aprendiendo. Sé que debería haber una opción para imprimir todo, pero es la declaración de O que estoy realmente atrapado. Estoy abierto a sed o grep si crees que es más eficiente. Cualquier ayuda o dirección es muy apreciada.
Para su entrada determinada, grep es suficiente
$ grep -o ''<.*>/|^--.*'' ip.html
<title>random text of the title 1</title>
--time--
<title>random text of the title 2</title>
--time--
<title>random text of the title 3</title>
--time--
<title>random text of the title 4</title>
--time--
-
-oextraer solo las partes correspondientes -
<.*>extracto de<hasta el último>en la línea -
/|^--.*patrón alternativo, si la línea comienza con--obtenga todo de esa línea
Para restringir solo a las etiquetas de title ,
grep -o ''<title.*title>/|^--.*'' ip.html