How to handle multiple rows in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to handle multiple rows in a file
# 1  
Old 05-09-2008
How to handle multiple rows in a file

I have a FILE a.txt which has the following data

113901.94,113901.94,56950.97,56950.97,NOT MATCHING,NOT MATCHING
10693.04,10693.04,5346.52,5346.52,NOT MATCHING,NOT MATCHING
1901.94,1901.94,550.97,550.97,NOT MATCHING,NOT MATCHING
103.04,103.04,53.52,53.52,NOT MATCHING,NOT MATCHING

#### This IS my Code ####

RECIPIENT="xyz@mail.com"
FILE_PATH=/path/
cd $FILE_PATH
FILE=a.txt
chmod 777 $FILE

tgt_dr=`cat a.txt | awk -F',' '{print $1}' $FILE`
tgt_cr=`cat a.txt | awk -F',' '{print $2}' $FILE`

src_dr=`cat a.txt | awk -F',' '{print $3}' $FILE`
src_cr=`cat a.txt | awk -F',' '{print $4}' $FILE`

### Comparing for the Credit Amount

if [ -s $FILE ]
then

if [ $src_cr -eq $tgt_cr ]
then
exit 0
else
(echo "Hi All,


The sum of credit amount : $src_cr
The sum of credit amount : $tgt_cr


Thanks
user_name" )|mailx -s "`date '+%d-%m-%y'` Credit Amount" $RECIPIENT
fi
else
exit 0
fi

### Comparing for the Debit Amount

if [ -s $FILE ]
then
if [ $src_dr -eq $tgt_dr ]
then
exit 0
else
(echo "Hi All,

The sum of debit amount : $src_dr
The sum of debit amount : $tgt_dr


Thanks
User_name" )|mailx -s "`date '+%d-%m-%y'` Debit Amount" $RECIPIENT
fi
else
exit 0
fi

as of now my program handle only one row. pl let me know how to achieve this in looping if i have
multiple lines in the a.txt file

Thanks
Babu
# 2  
Old 05-09-2008
This compares the whole file, writes all the credit problems to one file, all the debit problems to another, then sends all of the common problems in one email.
Code:
awk -F','   '{ if($1 != $3 ) {print $1, $3 > "debitfile"}
                  if($2 != $4 ) { print $2, $4 > "creditfile" }
                } ' a.txt
$(echo "Hi All,
`awk '{ printf( "The sum of credit amount :%10f   The sum of credit amount :%10f\n", $1, $2) creditfile`

Thanks
user_name" )|mailx -s "`date '+%d-%m-%y'` Debit Amount" $RECIPIENT
$(echo "Hi All,
`awk '{ printf( "The sum of debit amount :%10f   The sum of debit amount :%10f\n", $1, $2) debitfile`

Thanks
user_name" )|mailx -s "`date '+%d-%m-%y'` Debit Amount" $RECIPIENT

# 3  
Old 05-15-2008
Hi

The above solutions is fine if I have only four lines. I am not sure how many lines will be created in the output a.txt.

Pl let me know how to handle in looping
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How does extundelete handle multiple versions of the same inode?

Hi, I noticed a weird behavior in extundelete way to choose the filename to which it will restore a given inode. Here is an example : root@rescue:~# for after in '' 0 740 741 $(date -d 'now - 1 year' +%s); do rm -rf RECOVERED_FILES/; echo -e "$(date -d@$after 2> /dev/null || echo No... (4 Replies)
Discussion started by: chebarbudo
4 Replies

2. Shell Programming and Scripting

How to get multiple rows from a file?

Gents, I have a big file, where I would like to get some rows.. Then file1 contains. Obs_Report_Result : Shot_Report : ... (4 Replies)
Discussion started by: jiam912
4 Replies

3. UNIX for Dummies Questions & Answers

Write the total number of rows in multiple files into another file

Hello Friends, I know you all are busy and inteligent too... I am stuck with one small issue if you can help me then it will be really great. My problem is I am having some files i.e. Input.txt1 Input.txt2 Input.txt3 Now my task is I need to check the total number of rows in... (4 Replies)
Discussion started by: malaya kumar
4 Replies

4. Shell Programming and Scripting

connecting to table to extract multiple rows into file from unix script

I need to extract the data from oracle table and written the below code. But it is not working.There is some problem with the query and output is shown is No rows selected" . If I run the same query from sql developer there is my required output. And if I run the shell script with simple sql... (7 Replies)
Discussion started by: giridhar276
7 Replies

5. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

6. UNIX for Dummies Questions & Answers

how to handle multiple apps on host?

So, I'm going to install Oracle DB within my Suse host... Also, I would like to run Virtual Box and Tomcat.. ok, tomcat is going to be runnable app that will start at boot.. but, how to handle Oracle and virtual box? I would like to have an Oracle under it's own user, and to be able to use... (0 Replies)
Discussion started by: bongo
0 Replies

7. UNIX for Dummies Questions & Answers

Converting rows into multiple-rows

Hi every one; I have a file with 22 rows and 13 columns which includes floating numbers. I want to parse the file so that every five columns in the row would be a new record (row). For example, the first line in the old file should be converted into three lines with first two lines contain 5... (6 Replies)
Discussion started by: PHL
6 Replies

8. Shell Programming and Scripting

grep multiple rows from file.

Hi, I have file1 that contains many columns as show the first three below: "At1g29930" 198 2105 "At5g46430" 5569 9576 "At1g64740" 1908 2505 "At5g46430" 6717 11317 "At1g64740" 453 655 "At1g12470" 33 18 "At1g80680" 149 262 "At1g23040" ... (3 Replies)
Discussion started by: yifangt
3 Replies

9. Shell Programming and Scripting

Handle Configuration File with same name of Parameter in multiple Sections

Hi I have a config file with multiple section and a parameter with the same name in each section. I need to read each parameter for distinct section. Parameter = 1 .... Parameter = 2 .... Parameter = 4 .... Tried this: grep -m1 '^*ProcessorsNumber' ServiceBrokerFramework.cfg |... (7 Replies)
Discussion started by: potro
7 Replies

10. Shell Programming and Scripting

How to handle the Multiple Rows in the Database

Hi All, I have problem with database validations, actually my requirement is, my code will generate some seqno;s, which i have to check in database, whether the generated seqno;s are present in database or not, if the generated seqno;s are present in the database means, i need to generate... (2 Replies)
Discussion started by: hsekol
2 Replies
Login or Register to Ask a Question