ha********@hotmail.com (harry) wrote in message news:<10*************************@posting.google.c om>...
Hi Folks:
I'm trying to do something that looks simple, but I can't make it
work right.
It's Access 2000 on a Win2000 computer. I create a database with 5
columbs. The data I need to import is text. The way it's formatted
is one line each field, for the 5 fields, then to the next record.
The text file looks like this:
WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
...etc..
This is the first 3 records, 5 fields each. What I'm trying to make
it look like is something like this:
__________________________________________________ ___________________
WPTJ410 | MG | Active | 7/1/2011 | 10/15/2001 7:54:17 AM
KKC325 | IG | Active | 4/20/2013 | 3/1/2003 12:49:12 AM
WPNE621 | MG | Active | 5/12/2012 1:32:31 PM | 4/9/2002 12:51:12 AM
Something like that. I can enter the data by hand, just as it is in
the text file with the returns, and it works fine! Importing always
puts the data down the first columb. So does Copy/Paste. I use to do
this all the time with Microsoft Works..
Any help appreciated. I MUST be missing something. This should be
easy.
Thanks!
Harry
If you feel like taking a walk on the wild side:
'------------------begin weird.awk----------------
BEGIN {
# first create the line for the field names.
print "\"Field1\"" "," "\"Field2\"" "," "\"Field3\"" ","
"\"Field4\"" "," "\"Field5\"";
}
function deletefirstchar(astr)
{
# delete the first character of the string if the string has any
length
if (length(astr) == 0) {return astr}
astr = substr(astr,2)
return astr
}
function deletelastchar(astr)
{
# delete the last character of the string if the string has any length
if (length(astr) == 0) {return astr}
astr = substr(astr,1,length(astr) - 1)
return astr
}
function trim(myStr)
{
lenStr = length(myStr);
if (lenStr == 0)
{return myStr}
else
{
# Cull initial blanks and tabs
while (substr(myStr,1,1)==" " || substr(myStr,1,1)=="\t") {myStr =
deletefirstchar(myStr)}
if (lenStr==0) {return myStr}
# Cull final blanks
while (substr(myStr,length(myStr),1)==" ") {myStr =
deletelastchar(myStr)}
}
return myStr;
}
{
if (length($0) > 0)
{
{printf "%s" "\"" trim($0) "\""}
if (NR / 5.0 == int(NR / 5))
{printf "\n"}
else {printf "%s" ","}
}
}
END {}
'------------------end weird.awk----------------
data1.txt
WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
Command line: C:\Gawk> gawk -f weird.awk data1.txt > out.csv
out.csv
"Field1","Field2","Field3","Field4","Field5"
"WPTJ410","MG","Active","7/1/2011","10/15/2001 7:54:17 AM"
"KKC325","IG","Active","4/20/2013","3/1/2003 12:49:12 AM"
"WPNE621","MG","Active","5/12/2012 1:32:31 PM","4/9/2002 12:51:12 AM"
out.csv can be imported into Access as a comma delimited file and
making sure that the box is checked for field names on the first line.
If the data has any commas in it, it would be better to create a tab
delimited format. Dates can be imported as strings and changed to
Date/Time format in Access. Note that without trim() and its helper
functions this script would be about 16 lines long. Also note that
all the relevant files must be in C:\Gawk for the command line to work
as shown (gawk.exe, weird.awk and data1.txt).
James A. Fortune