A entrada é um arquivo (text.txt) contendo as seguintes linhas de texto (todos os espaços em branco são caracteres de espaço):
2016-10-24 10:25:48.939279-0400 0x63a55 Info 0x0 1416 backupd: (TimeMachine) [com.apple.TimeMachine.TMLogInfo] Found 2735 files (298.6 MB) needing backup
2016-10-24 10:25:48.954707-0400 0x63a55 Info 0x0 1416 backupd: (TimeMachine) [com.apple.TimeMachine.TMLogInfo] 6.08 GB required (including padding), 1.2 TB available
2016-10-24 10:27:56.721350-0400 0x63a55 Info 0x0 1416 backupd: (TimeMachine) [com.apple.TimeMachine.TMLogInfo] Copied 3128 items (283.1 MB) from volume Macintosh HD. Linked 5756.
2016-10-24 10:27:59.652854-0400 0x63a55 Info 0x0 1416 backupd: (TimeMachine) [com.apple.TimeMachine.TMLogInfo] Created new backup: 2016-10-24-102758
2016-10-24 10:27:59.638560-0400 0x64abb Error 0x0 52 UserEventAgent: (TimeMachine) [com.apple.TimeMachine.TMLogError] Failed to send message because the port couldn't be created.
2016-10-24 10:28:00.545654-0400 0x63a55 Error 0x0 1416 backupd: (TimeMachine) [com.apple.TimeMachine.TMLogError] Could not back up OS X Recovery to /Volumes/BackupA/Backups.backupdb: Error Domain=NSCocoaErrorDomain Code=-69830 "Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk" UserInfo={NSLocalizedDescription=Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk}
No exemplo acima, desejo produzir somente o carimbo de data / hora seguido por todo o texto após o último delimitador de colchetes.
Isso é o que eu quero do exemplo acima:
2016-10-24 10:25:48 Found 2735 files (298.6 MB) needing backup
2016-10-24 10:25:48 6.08 GB required (including padding), 1.2 TB available
2016-10-24 10:27:56 Copied 3128 items (283.1 MB) from volume Macintosh HD. Linked 5756.
2016-10-24 10:27:59 Created new backup: 2016-10-24-102758
2016-10-24 10:27:59 Failed to send message because the port couldn't be created.
2016-10-24 10:28:00 Could not back up OS X Recovery to /Volumes/BackupA/Backups.backupdb: Error Domain=NSCocoaErrorDomain Code=-69830 "Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk" UserInfo={NSLocalizedDescription=Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk}
Eu posso usar o cut , mas ele só pega coisas depois do delimitador.
Por exemplo, isto:
cat ~/Desktop/test.txt | grep TimeMachine | rev | cut -d']' -f1 | rev
... omite o carimbo de hora:
Found 2735 files (298.6 MB) needing backup
6.08 GB required (including padding), 1.2 TB available
Copied 3128 items (283.1 MB) from volume Macintosh HD. Linked 5756.
Created new backup: 2016-10-24-102758
Failed to send message because the port couldn't be created.
Could not back up OS X Recovery to /Volumes/BackupA/Backups.backupdb: Error Domain=NSCocoaErrorDomain Code=-69830 "Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk" UserInfo={NSLocalizedDescription=Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk}
Eu posso usar isso,
cat ~/Desktop/test.txt | grep TimeMachine | cut -c 1-19,140-
... mas os locais das colunas variáveis são um problema (observe as duas últimas linhas):
2016-10-24 10:25:48 Found 2735 files (298.6 MB) needing backup
2016-10-24 10:25:48 6.08 GB required (including padding), 1.2 TB available
2016-10-24 10:27:56 Copied 3128 items (283.1 MB) from volume Macintosh HD. Linked 5756.
2016-10-24 10:27:59 Created new backup: 2016-10-24-102758
2016-10-24 10:27:59ogError] Failed to send message because the port couldn't be created.
2016-10-24 10:28:00] Could not back up OS X Recovery to /Volumes/BackupA/Backups.backupdb: Error Domain=NSCocoaErrorDomain Code=-69830 "Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk" UserInfo={NSLocalizedDescription=Failed to get info for unmounted Recovery partition (error -69830): This operation requires an unmounted disk}
Tenho a sensação de que não há como usar cut para fazer o que eu quero, porque quero combinar a opção -c com a opção -d, e não consigo descobrir . Para onde devo ir daqui?