%20%E3%81%A8%20.bash_history%20%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%92%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%81%A6%201%20%E8%A1%8C%E3%81%AB%E4%BF%9D%E5%AD%98%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%E3%80%82%E3%82%A8%E3%83%9D%E3%83%83%E3%82%AF%E3%82%BF%E3%82%A4%E3%83%A0%E3%82%92%E5%90%AB%E3%82%80%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E3%81%BF%E3%81%8C%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82.png)
例: (.bash_history ファイル)
cd Fortigate_Report/
ll
exit
#1512031841
history>set1
#1512031849
history>set2
#1512031864
vi comm -23 <(sort set1) <(sort set2)
#1512031877
comm -23 <(sort set1) <(sort set2)
#1512031892
comm -23 <(sort set2) <(sort set1)
#1512031971
- これを別のファイルにコピーする必要があります(例:newfile.txt または任意の newfile)。
- ファイルはエポックタイムのないコマンドを無視するべきである
- そして、コマンドのないエポックタイムを無視するべきである
つまり、newfileの出力は次のようになります。
#1512031841 history>set1
#1512031849 history>set2
#1512031864 vi comm -23 <(sort set1) <(sort set2)
#1512031877 comm -23 <(sort set1) <(sort set2)
#1512031892 comm -23 <(sort set2) <(sort set1)
答え1
とsed
:
sed -n '/^#[0-9]\{1,\}$/N;s/\n/ /p' < file > newfile
答え2
testdata
サンプルデータを印刷します...
$ testdata() { cat<<dog
cd Fortigate_Report/
ll
exit
#1512031841
history>set1
#1512031849
history>set2
#1512031864
vi comm -23 <(sort set1) <(sort set2)
#1512031877
comm -23 <(sort set1) <(sort set2)
#1512031892
comm -23 <(sort set2) <(sort set1)
#1512031971
dog
}
...これは、タイムスタンプが見つかった場合にのみ反応するパイプに渡されますawk
。次に、次の行が読み込まれ、前に見つかったタイムスタンプが先頭に付けられて出力されます。
$ testdata | awk '/^#/ && (getline L) > 0 { print $0, L }'
#1512031841 history>set1
#1512031849 history>set2
#1512031864 vi comm -23 <(sort set1) <(sort set2)
#1512031877 comm -23 <(sort set1) <(sort set2)
#1512031892 comm -23 <(sort set2) <(sort set1)