Need a helping hand --stuck in starting of this problm.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a helping hand --stuck in starting of this problm.
# 1  
Old 09-14-2006
Need a helping hand --stuck in starting of this problm.

Hi all it is a real challenge for me to do it in 2 days any help or suggestion will be a great !
Problem : I have 17 - CSV files (Coma separated value)
each file conating around 26 column
the first line of each of the file conatin the field name and from second line
the file contain data for each of column heading.

for each of the file there are different mandatory column
like for BASIC_DATA there is mandatory column 1,2,3,4,5,6,10,11
this column must be having data for each of the rows if any of the columns don't have value then this file should be requested to resend .

Here is sample file structure of one of those file

'MBRASH','RMMG1-MTART','RMMG1-MATNR','MAKT-MAKTX','MARA-MEINS','MARA-MAKTL','MARA-BISMT','MARA-LABOR','MARA-KOSCH','MARA-PRDHA','MARA-MTPOS_MARA','MARA-EAN11','MARA-NUMTP','MARA-PRZUS','MARA-FERTH','MARA-NORMT','MARA-FORMT','MARA-WRKST','MARA-PROFL','MARA_KZUMW','MARA_IHIVI','MARA_ILOOS','MARA-ZEINR','MARA_SATNR','MARA_KZKFG'
Chemical,ZMAT-SFM,B12366497,PVAT66 BULK STRGE,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-SFM,B12366404,PVA 7130 BULK RC,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-SFM,B12366520,VAC BULK STRGE,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-FPM,D12766771,ELVANOL T66 22.7KG / 50 LB BAG,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-RM,D10270736,ACETIC ACID GLACIAL PLN,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-RM,D10000905,METHYL METHACRYLATE 99.5% TKT,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,
Chemical,ZMAT-RM,D10057585,DOW CORNING H-10 DEFOAMER DRM,KG,CHEM,,,,G2,NORM,,,,,,,,,,,,,,



The first row actually contain the column heading and the second row onward it contain data for it.

I want to find out if colume 1 ,column2 ,column 3 ,column 4, column 5,column 6 , column 10 ,column 11 has data for each of the row ??
if any row misses data for the mandatory column then
i should mail the owner that data missing.


Please need the help.
I want to write a function for this where i can pass the file name and the mandatory column for this file
# 2  
Old 09-14-2006
someone will help you soon with shell script,meanwhile, here's an alternative Python solution, am just bored. Smilie
Code:
import smtplib,glob
smtpserver = 'localhost' #define smtp server
fromaddr = "yourname@yoursite.org"
toaddr = "someone@somesite.org"
server = smtplib.SMTP(smtpserver) #instantiate
for files in glob.glob("*.csv"): #do all 17 csv files
	for num, lines in enumerate(open(files)):
 		lines = lines.strip() #strip new lines
 		splitted = lines.split(",") 
 		mandatory = splitted[0:6] + splitted[9:11] #get mandatory
  		if '' in mandatory: 
 			message = "Line number %d missing value in file %s" %(num, files)        
	        	server.sendmail(fromaddr, toadds, message)
server.quit() #close server


Last edited by ghostdog74; 09-14-2006 at 12:22 PM..
# 3  
Old 09-14-2006
this might help you
Code:
awk -F"," -v man_col="1,2,3,4,5,6,10,11" '
BEGIN { n = split( man_col,man_col_arr,",") }
{
        for( i = 1 ; i <= n ; ++i )
                if ( $man_col_arr[i] == "" )
                {
                        print NR
                        close(FILENAME)
                }
}' file

# 4  
Old 09-14-2006
Anbu,

Can you please explain your script?

Thanks
# 5  
Old 09-14-2006
if you are in windows platform and u have MS excel then i can suggest u something

open excel file-> open the csv file with excel-> then in excel go to -> data->filter->autofilter

then u can go and select the non-blanks from 1,2,3,4,5,6,10,11....if the count is different then there is something missing....


but this will only work f ur csv is small ....i.e not more than 5 mb....or lese u have to resolve it by script....i am working on it...will post later
# 6  
Old 09-14-2006
Code:
n = split( man_col,man_col_arr,",")

breaks man_col into pieces stored in successive elements of array man_col_arr, where the pieces lie between substrings matched by the regular expression ","

The function return value is the number of elements in the array man_col_arr

i/p : man_col="1,3,5"
o/p :
man_col_arr[1]=1
man_col_arr[2]=3
man_col_arr[3]=5

Code:
 if ( $man_col_arr[i] == "" )

here we are checking the mandatory field is empty.
If yes then print record number and then close the file.
# 7  
Old 09-14-2006
very simple soln

i think i have a very simple soution....

Code:
$ cat file | cut -f 25 -d',' | grep -v '^.' | wc -l

for checking every field just change the no. "25" to whatever col. no. u want to check (1,2,3,4,5,6,10,11) and then note the value. if it is non - zero then something must be missing....simple right???

do u really want to save the labour of changing the file name and the no ("25")....then a basic script can be written to automate the above command....do let us know..if it worked
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Helping a Newbie with Shell Homework

Good Evening, i got a homework where i have to list all files in the directory with the name length >=3 and <= 6 and after trying it for 2 days my Prof gave me a bit of code: #!/bin/bash for file in $(ls) do done after that he told me "now you only have to use wc and you got it" but... (1 Reply)
Discussion started by: Mentoss
1 Replies

3. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies

4. Shell Programming and Scripting

cut operation is not helping me much

hi, i have a file where I want to extract the the failure count only from the file. JOB_NAME STATE RUN_COUNT FAILURE_COUNT ------------------------------ --------------- ---------- ------------- OFS_BALA_BILLING_IN SCHEDULED 22992 ... (6 Replies)
Discussion started by: gotam
6 Replies

5. Shell Programming and Scripting

Helping in parsing subset of text from a big results file

Hi All, I need some help to effectively parse out a subset of results from a big results file. Below is an example of the text file. Each block that I need to parse starts with "reading sequence file 10.codon" (next block starts with another number) and ends with **p-Value(s)**. I have given... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. IP Networking

helping new Linux users remotely ?

I volunteer with a small charity which locally donates refurbished computers to people who normally could not afford their own computer. Most of these computers now have Linux on them. We are in the process of remastering Xubuntu 9.04 to use as our main distro from now on. In the past any time... (3 Replies)
Discussion started by: lagagnon
3 Replies

7. Shell Programming and Scripting

Need a hand. Please?

i have a script in sh. with awk, e.g. want to list all the contents of a subdirectory an a tabular way. ej: outoput directory1 subdirectory1 subdirectory2 subdirectory3 file1 filen file2 filez file2 ... filen+1 ... (1 Reply)
Discussion started by: alexcol
1 Replies
Login or Register to Ask a Question