Need help in Unix shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help in Unix shell script
# 1  
Old 07-19-2007
Need help in Unix shell script

Hi
I am new to this forum.I need a help in the following:
We receve pipe delimited file with
transaction ID,tran_date,Quest_cd,Ans_cd,ans_value.
Same transaction ID can be repeated with different quest_cd and ans_cd.

Basically I need to check if a perticular pair of quest_cd and ans_cd (say Q1234,A1234) is present under a transaction ,then another pair of quest_cd and ans_cd (say Q5678,A5678) should also be present.

Otherwise I need to remove the isolated row from input file and write to a bad file which should have the complete row in defect and with a comment that Q1234A1234 present but Q5678A5678 not present Or vice versa.

The balance good records sholud be written to a good file.

I hope I am clear in my explanation.As this is VERY urgent I appreciate immediate help
Regards
SRK
# 2  
Old 07-19-2007
Code:
As this is VERY urgent I appreciate immediate help

This is not appreciated.

Just a few pointers to help you Smilie

Code:
awk -F"," '{ if ( ( $3 == "Q1234 ) && ( $4 == "A1234" ) ) { print > "good.file" } else { print > "bad.file" } }' inputfile

Had you provided a snippet of the input file, it would have been even more helpful to you ! Smilie
# 3  
Old 07-19-2007
UNix Shell script help

Hi
Thanks for the repsonse . Your code looks at one line only for the Q/A pair but I need to look at two consecutive lines as below.(The file is a sorted file sorted on Tran Id)
AS per your suggestion I am giving few lines of my file:
991320070521330000000003|Q13251|A18741|234567890123456
671320070521330000000003|Q13251|A18741|456787654328977
671320070521330000000003|Q13260|A18765|4567890987654321234
471320070521330000000003|Q13260|A18765|2345678901234561

In the above the two lines with transaction ID 671320070521330000000003 should be written to a good file as they are having both pairs of Q/A and the other should be written to bad file with comments like below:

991320070521330000000003|Q13251|A18741|234567890123456 --> ONLY Driver's Licence is present Credit card number missing
471320070521330000000003|Q13260|A18765|2345678901234561 --> ONLY Credit card number is present Driver's Licence missing

Once again thanks for your help.
Regards
SRK
# 4  
Old 07-19-2007
Am sorry I don't understand your requirement really Smilie


Quote:
In the above the two lines with transaction ID 671320070521330000000003 should be written to a good file as they are having both pairs of Q/A and the other should be written to bad file with comments like below:
How do you say the tran id 671... should be written to good file, is there any selection condition for that ?

Because on all the 4 lines I could see Q/A pair.

Sorry about that, could you please explain a bit ?
# 5  
Old 07-19-2007
Hi
I am sorry for the confusion.The reason why the two lines with transaction id 671320070521330000000003 should be written to a good file is that they are having both the Q/A pairs ie.Q13251|A18741 and Q13260|A18765 while the other transactions are having either of these pairs but not both the pairs.I should read the file in a while loop and get the lines but I am not very clear in the code how to do that
Regads
SRK
# 6  
Old 07-19-2007
Code:
#! /opt/third-party/bin/perl

open(FILE, "<", "inputfile") || die "Unable to open file 'inputfile' <$!>";

while(<FILE>) {
  chomp;
  my @arr = split(/\|/);
  $fileHash{$arr[0]} .= ( "-" . $arr[1] . "-" . $arr[2] . "-" . $arr[3] );
}

close(FILE);

foreach my $k ( sort keys %fileHash) {
  my $val = $fileHash{$k};
  if ( $val =~ /Q13251/ && $val =~ /A18741/ && $val =~ /Q13260/ && $val =~ /A18765/ ) {
    ### Writing to good-file code
    print "$k $val in good-file\n";
  }
  else {
    ### Writing to bad-file code
  }
}

exit 0

# 7  
Old 07-19-2007
Hi
Thanks for your help.But unfortunately it has to be a UNIX korn shell script as otherwise the production support will not be able to handle any errors.
My sincere apologies for troubling you!
Regards
SRK
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

3. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

4. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

5. Shell Programming and Scripting

FTP from windows to unix server using unix shell script

Hi, Is it possible to ftp a huge zip file from windows to unix server using unix shell scripting? If so what command i need to use. thanks in advance. (1 Reply)
Discussion started by: Shri123
1 Replies

6. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

7. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

8. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question