Solved

VFP9 CSV Processing

Posted on 2010-11-11
5
336 Views
Last Modified: 2012-05-10
Hi all. I have a csv file which contains about 18,000 lines (records).
I need to remove all records where field #2 does not match "Florida".

The format is:

"Arthur","Florida", (+28 more fields)
"Phillips","Alaska", (+28 more fields)

I'm assuming CHR(13) + CHR(10) for line feed.

What do you suggest as the fastest method to process this file and remove all but Florida records?

Thanks!

0
Comment
Question by:formadmirer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 34114753
Following code should work. It is untested, missing error checks are on your own risk :-)
LOCAL lnH, lnOut, lcLine

lnH = FOPEN("YourFile")
lnOut = FCREATE("NewFile")

DO WHILE NOT FEOF(lnH)
  lcLine = FGETS(lnH, 8000)
  IF NOT ["Florida"] $ lcLine
    = FPUTS(lnOut, lcLine)
  ENDIF
ENDDO

= FCLOSE(lnH)
= FCLOSE(lnout)

Open in new window

0
 
LVL 42

Expert Comment

by:pcelba
ID: 34114784
Wow, it works in opposite way... and it does not check the second field and :-)

Wait a moment please
0
 
LVL 42

Accepted Solution

by:
pcelba earned 250 total points
ID: 34114829
Version 2:
LOCAL lnH, lnOut, lcLine, lnPos

lnH = FOPEN("YourFile")
lnOut = FCREATE("NewFile")

DO WHILE NOT FEOF(lnH)
  lcLine = FGETS(lnH, 8000)
  lnPos = AT(["], lcLine, 3)
  IF lnPos > 0 AND SUBSTR(lcLine, lnPos, 9) == ["Florida"]
    = FPUTS(lnOut, lcLine)
  ENDIF
ENDDO

= FCLOSE(lnH)
= FCLOSE(lnout)

Open in new window

0
 
LVL 27

Assisted Solution

by:CaptainCyril
CaptainCyril earned 250 total points
ID: 34116051
The way I would do it is this:

CREATE CURSOR import (name C(50), state C(50), field1, ..., field28)
APPEND FROM csv.csv TYPE CSV
DELETE FOR state = "Florida"
0
 

Author Closing Comment

by:formadmirer
ID: 34117028
I was gone and when I returned had a message saying that it would be best if multiple matches were allowed, meaning not matching just 'Florida', but other selected states as well.

Since this is not the question I posted, I think it's only fair to you that I close this question, awarding points evenly, and re-ask a new question.

Thanks!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question