Hi All!
Could anybody provide me with the fastest and best way to search for a specific value in a (VERY LARGE) CSV file and parse that exact line?
The CSV file has about 90.000 to 120.000 Lines and are build like this: - "84016","Bags","Belkin iPod Nano Remix Acrylcase black","19","Yes","0.1","F8Z381EA"
I would like to be able to finde "84016" and from there on parse the other values from that line.
Regards and thanks.
Frederik
Try something like this: - start_pos = Instr(1, csv_data, vbCrLf & Chr(34) & "84016")
-
If start_pos > 0 Then
-
'-- find the end of the line
-
end_pos = Instr(start_pos + 2, csv_data, vbCrLf)
-
-
'-- extract that one line based on start and end positions
-
onerow = Mid(csv_data, start_pos, end_pos - start_pos)
-
Else
-
'-- the searched data does not exist
-
End IF
-
The trick is to include the line break in your instr search, so you know you are at the beginning of the line.
Note: for best results, make sure there is a line break at the very beginning and the very end of the csv data.
6 2018
Try something like this: - start_pos = Instr(1, csv_data, vbCrLf & Chr(34) & "84016")
-
If start_pos > 0 Then
-
'-- find the end of the line
-
end_pos = Instr(start_pos + 2, csv_data, vbCrLf)
-
-
'-- extract that one line based on start and end positions
-
onerow = Mid(csv_data, start_pos, end_pos - start_pos)
-
Else
-
'-- the searched data does not exist
-
End IF
-
The trick is to include the line break in your instr search, so you know you are at the beginning of the line.
Note: for best results, make sure there is a line break at the very beginning and the very end of the csv data.
Thank you azrar!
The code works fine. But now I have one line and would like to extract elements from this, can you help me with that?
Given the line:
"84016","Bags","Belkin iPod Nano Remix Acrylcase black","19","Yes","0.1","F8Z381EA"
You can make array out of the data like this: - myArray = Split(csv_data,Chr(34) & "," & Chr(34))
The first and last element will have an extra quote in it. You can avoid that by tweaking the code I gave you earlier (add 1 to the start position, subtract 1 from the end position).
I disagree, I would use a db engine and query the csv - "select * from file where field1 = 84016"
The microsoft JET ODBC driver has that capability.
On the other hand, with 120 thousand rows, why haven't you converted to a db yet?
Jared
Thank you very much for that reply, I am trying to parse this file down to put the fields into a database. So i am looking for the exact thing you asked of..
I would be very thankfull if you could guide me further.
Regards
Frederik
Sign in to post your reply or Sign up for a free account.
Similar topics
by: hue |
last post by:
I am trying to parse command line options using getopt module.
I have written the following Code
import string
import getopt
def usage():
print '''haarp_make.py -- uses getopt to...
|
by: supster |
last post by:
I'de like to change only a specific line of a textbox.
Right now I am doing:
string texta = mainTextBox.Text.Split(
"\n".ToCharArray() );
for ( int i = 0; i <= texta.Length-1; i++ )
{
|
by: Xero |
last post by:
Hello.
How do you erase a specific line in a *.txt file?
Thanks in advance.
--
Xero
http://www.chezjeff.net
My personal web portal
|
by: kevin arana |
last post by:
Hello.
Could anyone please show me an example of how to retrieve a specific line of
a text file (say line 3 of data.txt) into a string variable?
I have seen many examples on how to dump all...
|
by: frankleggett |
last post by:
Hi
Excuse my ignorance but I am trying to write a very simple program. It needs to be simple because of my lack of knowledge. Anyway I would like to input a specific line from a textfile without...
|
by: uche |
last post by:
Hello all!!
Is there an algorithm out there that will allow you to go to a
specific line in a .txt...and start outputing to the screen at that
line until end of record
Here is a code that i...
|
by: Rajgodfather |
last post by:
I am getting the end couldn't error while validating xml file against xsd.
The xml file looks perfect.
XML:
<event id="1">
<!--
Successful event.
-->
...
|
by: jo3c |
last post by:
hi everybody
im a newbie in python
i need to read line 4 from a header file
using linecache will crash my computer due to memory loading, because
i am working on 2000 files each is 8mb
...
|
by: Patrick David |
last post by:
Hello NG,
I am searching for a way to jump to a specific line in a text file, let's
say to line no. 9000.
Is there any method like file.seek() which leads me to a given line instead
of a given...
|
by: Ramesh |
last post by:
Hello,
I am using the ofstream class to create a text file with keys and
values like:
Key1=Value10
Key2=Value15
Key3=Value20
In case I need to set a new value for Key2, say value50 - I am...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |