com sed
:
sed -n '/^#[0-9]\{1,\}$/N;s/\n/ /p' < file > newfile
por exemplo (arquivo .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
ou seja, newfile A saída deve ser assim
#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)
com sed
:
sed -n '/^#[0-9]\{1,\}$/N;s/\n/ /p' < file > newfile
testdata
imprimirá seus dados de exemplo ...
$ 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
}
... que, então, será canalizado para awk
, que reage apenas se for visto um timestamp. Em seguida, a próxima linha será lida e impressa com o prefixo timestamp visto antes:
$ 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)