
Posso comparar dois arquivos de texto ignorando N símbolos do início de cada linha?
Por exemploarquivo1:
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.
earquivo2:
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.
Se eu comparar dois arquivos linha por linha, eles serão diferentes por causa dos segundos no carimbo de data/hora.
Mas se eu pular os primeiros 19 símbolos do início de cada linha em ambos os arquivos (data e hora) - esses arquivos serão idênticos. Como fazer isso usando o comando shell (script)?
Muito obrigado antecipadamente.
Responder1
Usando cut
:
diff <(cut -c 20- file1) <(cut -c 20- file2)
Nota: com GNU, cut
a -c
opção de caractere realmente funciona em bytes e não em caracteres, mas isso deve funcionar, desde que sua saída comece com carimbos de data/hora e não com caracteres especiais.