Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete data or lines in a file 1

Status
Not open for further replies.

zanzemaj

Programmer
Nov 2, 2006
35
NZ
I have a file stream.txt and I need to disregard the lines STREAM TOTALS and lines after that. But I want to include all lines with ARCHIVING DATABASE and lines after that.
Code:
[small]
06/15/2007 22:18:51 ARCHIVING DATABASE "BACKUP_CONTROL_DEV"
06/15/2007 22:18:53 TABLE "ARCHIVE_DB" - 438 BYTES, 0 ROWS ARCHIVED FOR THIS  STREAM
06/15/2007 22:18:53 TABLE "ARCHIVE_TABLES" - 438 BYTES, 0 ROWS ARCHIVED FOR  THIS STREAM
06/15/2007 22:18:53 TABLE "BACKUP_CYCLE_CONTROL" - 438 BYTES, 0 ROWS ARCHIVED  FOR THIS STREAM
06/15/2007 22:18:53 TABLE "EVENTS_MEDIA_SIB_LOAD" - 438 BYTES, 0 ROWS ARCHIVED  FOR THIS STREAM
06/15/2007 02:28:47  TABLE "nmmp_" -  18,015,000 BYTES, 342,712 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47  
06/15/2007 02:28:47  STREAM TOTALS:
06/15/2007 02:28:47  TABLE "dsd_zation" -   8,711,188,670 BYTES, 150,192,895 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc" - 317,632,067 BYTES,   1,200,084 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "lu_upc_usa" - 229,112,147 BYTES, 865,803 ROWS ARCHIVED TOTAL
06/15/2007 02:28:47  TABLE "dsd_zation" -   4,355,943,498 BYTES, 75,102,461 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47  TABLE "lu_xxx" - 158,866,056 BYTES, 600,190 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 22:18:58 TABLE "TXN_ITEM_MKDN_DAILY_CNT" - 620 BYTES, 0 ROWS  ARCHIVED TOTAL
06/15/2007 22:18:58 "BACKUP_CONTROL_DEV" - LOCK RELEASED
06/15/2007 22:18:58
06/15/2007 22:18:58 ARCHIVING DATABASE "DBA_INFO"
06/15/2007 22:19:01 TABLE "Accountinfo" - 57,757 BYTES, 725 ROWS ARCHIVED FOR  THIS STREAM
06/15/2007 22:19:01 TABLE "AccountInfo_V2R4" - 53,312 BYTES, 644 ROWS  ARCHIVED FOR THIS STREAM
06/15/2007 22:19:05 TABLE "AllRights" - 44,077,114 BYTES, 477,103 ROWS  ARCHIVED FOR THIS STREAM
06/15/2007 22:19:05 TABLE "canary" - 80,438 BYTES, 5,000 ROWS ARCHIVED FOR  THIS STREAM
[/small]
I need the output as
Code:
[small]
06/15/2007 22:18:51 ARCHIVING DATABASE "BACKUP_CONTROL_DEV"
06/15/2007 22:18:53 TABLE "ARCHIVE_DB" - 438 BYTES, 0 ROWS ARCHIVED FOR THIS  STREAM
06/15/2007 22:18:53 TABLE "ARCHIVE_TABLES" - 438 BYTES, 0 ROWS ARCHIVED FOR  THIS STREAM
06/15/2007 22:18:53 TABLE "BACKUP_CYCLE_CONTROL" - 438 BYTES, 0 ROWS ARCHIVED  FOR THIS STREAM
06/15/2007 22:18:53 TABLE "EVENTS_MEDIA_SIB_LOAD" - 438 BYTES, 0 ROWS ARCHIVED  FOR THIS STREAM
06/15/2007 02:28:47  TABLE "nmmp_" -  18,015,000 BYTES, 342,712 ROWS ARCHIVED FOR THIS STREAM
06/15/2007 02:28:47  
06/15/2007 22:18:58 ARCHIVING DATABASE "DBA_INFO"
06/15/2007 22:19:01 TABLE "Accountinfo" - 57,757 BYTES, 725 ROWS ARCHIVED FOR  THIS STREAM
06/15/2007 22:19:01 TABLE "AccountInfo_V2R4" - 53,312 BYTES, 644 ROWS  ARCHIVED FOR THIS STREAM
06/15/2007 22:19:05 TABLE "AllRights" - 44,077,114 BYTES, 477,103 ROWS  ARCHIVED FOR THIS STREAM
06/15/2007 22:19:05 TABLE "canary" - 80,438 BYTES, 5,000 ROWS ARCHIVED FOR  THIS STREAM
[/small]
 
One way with awk:
awk '/ARCHIVING DATABASE/{f=1}/STREAM TOTALS/{f=0}f' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV for your response. I was tweaking a while ago and this also works:
sed -n "/ARCHIVING DATABASE/,/STREAM TOTALS/p" stream.txt
 
I thought the STREAM TOTALS line should be disregarded too ...
 
Yes and your solution does that. I was thinking that I can issue another command to take that line away for sed.

Thank you for your solution since it does the requirement in one step.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top