
¿Puedo comparar dos archivos de texto omitiendo N símbolos desde el inicio de cada línea?
Por ejemploarchivo1:
2018-05-31 12:00:00 This is the first line of text.
2018-05-31 12:00:00 This is the second line of text.
2018-05-31 12:00:00 This is the third line of text.
2018-05-31 12:00:00 This is the forth line of text.
2018-05-31 12:00:00 This is the fifth line of text.
yarchivo2:
2018-05-31 12:00:01 This is the first line of text.
2018-05-31 12:00:02 This is the second line of text.
2018-05-31 12:00:03 This is the third line of text.
2018-05-31 12:00:04 This is the forth line of text.
2018-05-31 12:00:05 This is the fifth line of text.
Si comparo dos archivos línea por línea, son diferentes debido a los segundos en la marca de tiempo.
Pero si me salto los primeros 19 símbolos desde el inicio de cada línea en ambos archivos (fecha y hora), estos archivos son idénticos. ¿Cómo hacer eso usando el comando Shell (script)?
Muchas gracias por adelantado.
Respuesta1
Usando cut
:
diff <(cut -c 20- file1) <(cut -c 20- file2)
Nota: con GNU, cut
la -c
opción de caracteres en realidad funciona en bytes, no en caracteres, pero esto debería estar bien siempre y cuando su salida comience con marcas de fecha/hora y no con caracteres especiales.