
各行の先頭から N 個のシンボルをスキップして 2 つのテキスト ファイルを比較できますか?
例えばファイル1:
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.
そしてファイル2:
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.
2 つのファイルを行ごとに比較すると、タイムスタンプの秒数が異なるため異なります。
しかし、両方のファイル(日付と時刻)の各行の先頭から最初の 19 個のシンボルをスキップすると、これらのファイルは同一になります。シェル コマンド(スクリプト)を使用してこれを実行するにはどうすればよいですか?
事前にどうもありがとうございました。
答え1
使用方法cut
:
diff <(cut -c 20- file1) <(cut -c 20- file2)
注: GNU では、文字オプションcut
は-c
実際には文字ではなくバイトに対して機能しますが、出力が特殊文字ではなく日付/時刻スタンプで始まっている限り、これは問題ありません。