If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > reading a column value from a text file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 21:05
gomes009 gomes009 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
reading a column value from a text file

I am trying to compare two values from different sources and store the result into a shell variable. FileA has 4500 records in this example. I want to count the number of records in FileA and compare that with totalcount_fileA column in FileB

FileB file format is as follows: The file will not contain the column names.

SourceName source_date totalcount_fileA filedate,
Hello 12/04/2003 4500 2/04/2003


Any help is appreciated
Reply With Quote
  #2 (permalink)  
Old 02-11-04, 02:09
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Try and adapt the following code :

Code:
CountA=`wc -l FileA | awk '{ print $1}'`
CountB=`awk 'NR==2 {print $3;next}' FileB`
if [ $CountA -eq $CountB ]
   then echo "Ok"
   else echo "Counts does'nt match"
fi
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 02-11-04, 05:20
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: reading a column value from a text file

Quote:
FileB file format is as follows: The file will not contain the column names.

SourceName source_date totalcount_fileA filedate,
Hello 12/04/2003 4500 2/04/2003
Are you saying that there may be many FileA, and FileB contains the expected record count for each FileA value?

If so, this might help you...
Code:
awk '
{
 fname=$1; fcount=$3
 "wc -l "fname | getline # this pipes the system call to 'wc'
                         # the stdout is read in to replace $0
 print fname " - Expected count: "fcount"; Actual Count: "$1
}' FileB
Damian
Reply With Quote
  #4 (permalink)  
Old 02-11-04, 06:06
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Sorry, FileB not contain the column names.

Code:
CountA=`wc -l FileA | awk '{ print $1}'`
CountB=`awk '{print $3;exit}' FileB`
if [ $CountA -eq $CountB ]
   then echo "Ok"
   else echo "Counts does'nt match"
fi
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 02-11-04, 21:12
gomes009 gomes009 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
Thanks, it worked. I appreciate.
Reply With Quote
Reply

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

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