同じ列の値を比較し、新しい列に直接出力

同じ列の値を比較し、新しい列に直接出力

私の入力ファイルは

DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11  110005
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11  110006
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343214 11  110007
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843914 11  110009
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945414  11  110010
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343314 11  110013
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945614  11  110015
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0941 29343514 11  110019
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 0941 7446214  11  110021
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945814  11  110022
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 0941 7446414  11  110024

私の要件は、出力が次のようになることです

DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11 110005  0
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11 110006  0
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343214 11 110007  0
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843914 11 110009  1
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945414  11 110010  0
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343314 11 110013  2
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945614  11 110015  1
DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0941 29343514 11 110019  3
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 0941 7446214  11 110021  1
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 2336 7945814  11 110022  0 
DPortal=ECCN RemoteFile=4004_120306 1232 A03 141111 0941 7446414  11 110024  1

つまり、最後の列は最後の列の次の行に-1の値を出力しなければなりません。すなわち、(n+1)-n-1=次の列である。

ベストアンサー1

この試み:

awk 'NR==1{last=$NF-1}{print $0,$NF-last-1; last=$NF}' file

最初の行では、始めるためにlast最後のフィールドの値から1()を引いた値に変数を設定します。$NF-1後で前の行の値のみをlast取得します。$NF

おすすめ記事