The UNIX Forums  



Go Back   The UNIX Forums > Top Forums > Shell Programming and Scripting
Home Forums Register Rules & FAQDonate Members List Search Today's Posts Mark Forums Read

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: Apr 2008
Location: Bangalore
Posts: 14
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 1 Week Ago
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 3,030
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #3 (permalink)  
Old 2 Days Ago
Registered User
 
Join Date: Apr 2008
Location: Bangalore
Posts: 14
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
flexible sed command needed to handle multiple input types SiftinDotCom Shell Programming and Scripting 2 03-19-2008 02:39 PM
Handle Configuration File with same name of Parameter in multiple Sections potro Shell Programming and Scripting 7 03-05-2008 09:36 AM
a bit tricky to change it multiple rows in one row and ... netbanker Shell Programming and Scripting 2 12-31-2007 11:48 PM
How to handle the Multiple Rows in the Database hsekol Shell Programming and Scripting 2 03-05-2007 06:51 AM
NFS file handle kazimir UNIX for Advanced & Expert Users 2 07-24-2002 11:11 AM


web tracker

All times are GMT -5. The time now is 01:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
UNIX Forum Content Copyright ©1993-2008 SilkRoad Asia All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93