Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-12-2004, 04:03 PM
|
#1
|
|
Member
Registered: Jul 2001
Location: Earth
Posts: 164
Rep:
|
Flat File QC Scripting
Hi All, need some help.
I have a linux server that runs php/mysql etc... I'm trying to automate the QC process on various Flat File formats (txt, csv).
All I really need to do is verify the total record length for aeach line of data.
Anyone have any ideas about what type of script I will be able to use to do this. Also, if it's a script I can have run via the web server, that would be great also.
Thanks for any input in advance----
mychl
|
|
|
|
02-13-2004, 03:10 AM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
I don't even know what QC is :}
Cheers,
Tink
|
|
|
|
02-13-2004, 08:19 AM
|
#3
|
|
Member
Registered: Jul 2001
Location: Earth
Posts: 164
Original Poster
Rep:
|
Quality Control.... basically just verifying the data....

|
|
|
|
02-13-2004, 11:18 AM
|
#4
|
|
Member
Registered: May 2002
Posts: 964
Rep:
|
This is a start:
Code:
#!/bin/sh
# script: linecnt
# the $1 parameter is the file name
# usage: linecnt <file name>
echo "Line counts for $1"
let counter=0
while read rec
do
counter=`expr $counter + 1`
echo "$counter: `echo $rec | wc -c`"
done < $1
# eof
|
|
|
|
02-15-2004, 02:19 PM
|
#5
|
|
Member
Registered: Jul 2001
Location: Earth
Posts: 164
Original Poster
Rep:
|
Thanks Jim, that gave me a good start.....
Works great for TEXT format, now I'm working on CSV.
I'll post what I work out....
Thanks again!
|
|
|
|
02-20-2004, 11:53 AM
|
#6
|
|
Member
Registered: Jul 2001
Location: Earth
Posts: 164
Original Poster
Rep:
|
Here is what I came up with, using perl...
[code]
#!/usr/bin/perl
########################################################################
open(LOGFILE, ">QC_TXT_LOG.log");
print LOGFILE "Begin Parsing All TXT Files\n";
print LOGFILE "========================================\n\n";
# Scan Parent Directory for Sub-Folders
opendir(MAIN, ".");
@dirs=(readdir(MAIN));
closedir(MAIN);
#######################################################################
# Recurse into sub-folders
foreach $dir(@dirs){
if(-d "$dir"){
print LOGFILE "Profile: $dir\n";
print LOGFILE "===============================\n";
opendir(DIR, "$dir");
@files=grep(/\.TXT$/|/\.txt$/,readdir(DIR));
closedir(DIR);
$linecount=0;
foreach $file(@files){
@fileinfo=stat("$dir/$file");
$filesize=((@fileinfo[7])/1000);
$filedate=localtime(@fileinfo[9]);
print LOGFILE "\tFilename: $file\n";
print LOGFILE "\tFile Size: $filesize Kb\n";
print LOGFILE "\tFile Date: $filedate\n";
$linecount=0;
open FILE, "$dir/$file";
while (<FILE>){
$linecount++;
if($.==1){
$first_length=length($_);
print LOGFILE "\t\tRecord Length:\t$first_length\n";
}
$lcount=length($_);
if($lcount!=$first_length){
print LOGFILE "***Line:$. Count:$lcount DOES NOT MATCH PROFILE***\n";
}
}
close FILE;
print LOGFILE "\t\tRecord Count:\t$linecount\n";
}
print LOGFILE "===============================\n";
}
}
[\code]
This script saves my staff and I about 4 hours of work every week......
wahoooooooooooooooo
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:02 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|