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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove duplicate record and Extract specific field

Status
Not open for further replies.

nguyenb9

Technical User
Apr 1, 2003
55
US
Hi!,
I have a file with duplicate record and I would like to remove one record and save it to a file. Then I would like to extract specific field from a new saved file. Example as follows:

1. Input file with duplicate record:
PASSWORD SUCCESS: The password for user SNGUYEN has been changed.
PASSWORD SUCCESS: The password for user SNGUYEN has been changed.

2. Remove duplicate record and save it to file:
PASSWORD SUCCESS: The password for user SNGUYEN has been changed.

3. Extract a specific field, and the output file should like this:
PASSWORD SUCCESS

Thank you,



 
Are the duplicate records always going to be one behind the other? Are you looking to remove the record from the original file and place just the filtered result in a second file? If so, here is a script that does that:

proc main
string sLine
string sPrevLine
integer iLen
long lLen
string sTemp

if fopen 0 "test.txt" READWRITE
while not feof 0
fgets 0 sLine
if not strcmp sLine sPrevLine
sPrevLine = sLine
else
strlen sLine iLen
lLen = iLen
fseek 0 (-lLen) 1
fdelblock 0 iLen
ftell 0 lLen
fclose 0
fopen 0 "test.txt" READWRITE
fseek 0 lLen 0
fopen 1 "test2.txt" APPEND
strtok sTemp sLine ":"
fputs 1 sTemp
endif
endwhile
fclose 0
endif
endproc

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top