Data and return code extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Data and return code extraction
# 1  
Old 11-25-2010
Data and return code extraction

Hello everybody,

Another day another problem.

I have to create a script which collects data from 3 csv files.

I would like the script to check file1 which contains different values for the date entered previously. As you can see 01/12/2010 contains actions in the first field and in the second field a sub action (XXXZZ24), this sub action is the common element of the three csv files:

Code:
01/12/2010;;;
Action_1;"XXXZZ24";Comment1;"Comment2"
Action_2;"XXXZZ25";Comment1;"Comment2"
Action_3;"XXXZZ26";Comment1;"Comment2"
Action_4;"XXXZZ27";Comment1;"Comment2"
Action_5;"XXXZZ28";Comment1;"Comment2"
Action_6;"XXXZZ29";Comment1;"Comment2"
Action_7;"XXXZZ30";Comment1;"Comment2"
02/12/2010;;;
Action_8;"XXXZZ31";Comment1;"Comment2"
Action_9;"XXXZZ32";Comment1;"Comment2"
Action_0;"XXXZZ33";Comment1;"Comment2"
Action_1;"XXXZZ24";Comment1;"Comment2"
Action_5;"XXXZZ35";Comment1;"Comment2"
Action_6;"XXXZZ36";Comment1;"Comment2"
Action_2;"XXXZZ25";Comment1;"Comment2"

The second file contains actions and sub actions (for instance Action_1 is related to sub action XXXZZ24 and XXXZZ44) :

Code:
Action_1; XXXZZ24
Action_1; XXXZZ44
Action_2; XXXZZ25
Action_6; XXXZZ29
Action_3; XXXZZ26
Action_7; XXXZZ30

Finally, the third file contains actions and sub actions as well as hours of execution and return codes (return code is in the 7th field) :

Code:
"2010/12/02 12:31:54 	End of job";;;;;;;;;
LANCEUR;XXX7724;02/12/2010;12:31:22;02/12/2010;12:32:01;0;;Comment;Traces

Would anyone know how to make a script which :

- asks for a date
- then shows actions and sub actions from file1 for a specific date
- then matches actions and sub actions from the first file with the second file (assuming one action can have multiple sub actions)
- and finally matches the result of the 2 first files with the execution of the actions and sub actions which occured for a specific date in the third one.

The result of all this would be :

Code:
02/12/2010 :

"sub action" from "Action_1" executed succesfully (or not (depending on the return code (0 is OK, 1 is abnormal, and 3 is KO)) started at "hh:mm:ss" and ended at "hh:mm:ss"

I know it is a little bit tricky and I may not have made myself really clear but any help would be greatly appreciated.

Thanks Smilie
# 2  
Old 11-25-2010
Added 1 record to your file3 so we get some output:

Code:
$ cat file3
"2010/12/02 12:31:54    End of job";;;;;;;;;
LANCEUR;XXX7724;02/12/2010;12:31:22;02/12/2010;12:32:01;0;;Comment;Traces
LANCEUR;XXXZZ24;02/12/2010;12:31:22;02/12/2010;12:32:01;0;;Comment;Traces
 
$ cat show
awk -F"[; ]" -v D=$1 '
BEGIN { printf "%s :\n\n", D }
FNR == 1 { file++}
file == 1 {
   if ($2 == $3) Active=($1==D);
   else if (Active) {
       # remove quotes
       $2=substr($2,2,length($2)-2);
       A[$2]=$1;
   }
}
file==2 && $3 in A { B[$3]=A[$3]; }
file==3 && $3=D && $2 in B {
    printf "\"%s\" from \"%s\" ", $2, B[$2]
        printf $7==0?"executed succesfull ":"failed to complete "
        printf "started at \"%s\" and ended at \"%s\"\n", $4, $6
}
' file1 file2 file3
 
$ ./show 02/12/2010
02/12/2010 :
 
"XXXZZ24" from "Action_1" executed succesfull started at "12:31:22" and ended at "12:32:01"

# 3  
Old 11-26-2010
Thanks a lot,

Unfortunately I get the error below :

Code:
 syntax error The source line is 16.
 The error context is
                        printf >>>  $7== <<< 0?"executed succesfull ":"failed to complete "
 awk: The statement cannot be correctly parsed.
 The source line is 16.

Any idea ?
# 4  
Old 11-26-2010
Code:
printf "%s", $7==0?"executed succesfull ":"failed to complete "

?
# 5  
Old 11-26-2010
if you use solaris you should nawk instead of awk. check your Man pages.
# 6  
Old 11-26-2010
Thanks for your help.

The problem is I don't use solaris, I am under HP-UX and I still have the same error :

Code:
syntax error The source line is 16.
 The error context is
                        printf "%s", >>>  $7== <<< 0?"executed succesfull ":"failed to complete "
 awk: The statement cannot be correctly parsed.
 The source line is 16.

# 7  
Old 11-26-2010
Code:
c=(($7==0)?"executed succesfull ":"failed to complete ")
printf "%s", c

?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CSV file data extraction

Hi I am writing a shell script to parse a CSV file , in which i am facing a problem to separate the columns . Could some one help me with it. IN301330/00001 pvavan kumar limited xyz@ttccpp.com IN302148/00002 PRECIOUS SECURITIES (P) LTD viash@yahoo.co.in IN300239/00000 CENTRE india... (8 Replies)
Discussion started by: nanduri
8 Replies

2. UNIX for Dummies Questions & Answers

Need help for data extraction if files

Hello all, I want to extract some particular data from a files and than add all the values . but i m not able to cut the particular word(USU-INOCT and USU-OUTOCT) as it is coming not in column. and than able to add values coming in it . can anyone help me Please cat <file name> ... (7 Replies)
Discussion started by: anamdev
7 Replies

3. Shell Programming and Scripting

data extraction from a file

Hi Freinds, I have a file1.txt in the following format File1.txt I want to get 2 files from the above file filextra.txt should have the lines which are ending with "<" and remaining lines in the filecompare.txt file. Please help. (3 Replies)
Discussion started by: i150371485
3 Replies

4. Shell Programming and Scripting

Data Extraction problem in perl

Hello, I want to extract the words from a file which starts with SRD-R or SRD-DR. I have written a script which is able to trace the word but it is printing the whole line. sub extract_SRD_tag{ my ($tag, $app, $path, @data, $word ); $path = shift; $app = shift; open (FILE, $path) or... (2 Replies)
Discussion started by: suvendu4urs
2 Replies

5. Shell Programming and Scripting

Data extraction in perl variable

HI, i have variable in perl like below $tmp="/home/sai/automation/work/TFP_GN.txt" it can conatain any path its filled from config file. now i want extarct the path upto this /home/sai/automation/work/ and put it in another variable say... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

6. Shell Programming and Scripting

Another data extraction question

Hi, I have a tmp file like below: <ADATA> ANUM=900 ADESC=Saving ATYP=0 TXREGD=0 </ADATA> <ADATA> ANUM=890 ADESC=Saving ATYP=0 ABAL=9000 TXREGD=1 </ADATA> <ADATA> (6 Replies)
Discussion started by: kunigirib
6 Replies

7. Shell Programming and Scripting

Data Extraction From a File

Hi All, I have a requirement where I have to search the file with some text say "Exception". This exception word can be repeated for more then 10 times. Suppose the "Exception" word is repeated at line numbers say x=10, 50, 60, 120. Now I want to extract all the lines starting from x-5 to... (3 Replies)
Discussion started by: rrangaraju
3 Replies

8. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

9. Shell Programming and Scripting

help with data extraction script

Hello all, Iam newbie here and to unix programming. I have the following text file. A:Woshington,B:London,C:Paris,D:Manchester,C:Lisbon,E:Cape town. Now I would like extract this and store in database. here is the script I have tried but it did work. CITY1:`echo "$text" | grep "A:"... (11 Replies)
Discussion started by: mam
11 Replies

10. Shell Programming and Scripting

Data Extraction issue.

I have a small problem, I have written a following script, which extracts all the rows from source file which strats with T101 and rights it to another file mydata.dat Script my_script #!/bin/ksh YMONTH=$1 dir1='/home/data' dir2='/clients/source_file' cd $dir1 grep "T101"... (5 Replies)
Discussion started by: irehman
5 Replies
Login or Register to Ask a Question