rowcnt except Header & Footer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rowcnt except Header & Footer
# 1  
Old 08-03-2007
rowcnt except Header & Footer

Hi Gurus,

My requirement is, I am passing a file1.dat into this(rowcnt.sh) script,but returning a wrong value of -2.(it should be 4).Becoz my file1.dat contains 6records incl: Header & Footer.(6-2=4)

wrong output:
-------
#sh rowcnt.sh file1.dat
-2 actual_cnt except HDR & FTR

should be:
-------
#sh rowcnt.sh file1.dat
4 actual_cnt except HDR & FTR

my script:
=======
rowcnt.sh
-------
PARA1=$1 #input_file file1.dat
SOURCE_FILE_NAME=`echo ${PARA1}`
ACTUAL_CNT=`wc -l $SOURCE_FILE_NAME` # Count records in the data file
ACTUAL_CNT1=`$ACTUAL_CNT |awk -F ' ' '{print$1}'`
ACTUAL_CNT2=$ACTUAL_CNT1-2 # total no of records-2(Hdr & Ftr)
echo $ACTUAL_CNT2 "actual_cnt except HDR & FTR"
exit 1
--------------------------------------------------

Pl advise.Bit urgent. Thanks a lot....
# 2  
Old 08-03-2007
you have posted in the wrong forum

this thread needs to be moved

any way try this,

Code:
awk '{}END{ print NR - 2 }' filename

# 3  
Old 08-03-2007
Modified your code

rowcnt.sh
-------
Code:
PARA1=$1 #input_file file1.dat
SOURCE_FILE_NAME=`echo ${PARA1}`
ACTUAL_CNT=`wc -l $SOURCE_FILE_NAME` # Count records in the data file
ACTUAL_CNT1=`echo $ACTUAL_CNT |awk '{print $1}'`
ACTUAL_CNT2=$((ACTUAL_CNT1-2)) #total no of records-2(Hdr & Ftr)
echo $ACTUAL_CNT2 "actual_cnt except HDR & FTR"
exit 1

or you can use like

Code:
PARA1=$1 #input_file file1.dat
SOURCE_FILE_NAME=`echo ${PARA1}`
ACTUAL_CNT=`awk 'END{ print NR -2}' $SOURCE_FILE_NAME`
echo $ACTUAL_CNT "actual_cnt except HDR & FTR"
exit 1

# 4  
Old 08-03-2007
Great all,

It works great....

Thks...........
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip header and footer

Hi I have below requirements on the script below : (1) I receive 2 pipe seperated file called OUT.psv and DIFF.psv with a column header.I concatenate the 2 files and create a final.psv file. I want to add another header as START_FILE to the final.psv file . How to achieve this ? (2) I have... (5 Replies)
Discussion started by: samrat dutta
5 Replies

2. Programming

[solved] how to remove header and footer

it still display header and footer header SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 24 13:41:51 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production With the Partitioning, Real... (0 Replies)
Discussion started by: ment0smintz
0 Replies

3. Shell Programming and Scripting

Removing header or footer from file

Hi Every one, what is the coomand to remove header or footer from a file. Please help me by providing command/syntax to remove header/footer from unix. Thanks in advance for all your support. (5 Replies)
Discussion started by: sridhardwh
5 Replies

4. Shell Programming and Scripting

Add header and footer with record count in footer

This is my file(Target.txt) name|age|locaction abc|23|del xyz|24|mum jkl|25|kol The file should be like this 1|03252012 1|name|age|location 2|abc|23|del 2|xyz|24|mum 2|jkl|25|kol 2|kkk|26|hyd 3|4 Column 1 is row indicator for row 1 and 2, column indicator is 1,for data rows... (1 Reply)
Discussion started by: itsranjan
1 Replies

5. Shell Programming and Scripting

Removing header and footer

I have two files which are getting sent to a UNIX server in order to be bcp'd into a database. The bcp is failing because there's a header and footer row on the file which give the date of the file and the number of rows in it. That's because the file is also being used for another process, so we... (1 Reply)
Discussion started by: Tom Sawyer
1 Replies

6. Shell Programming and Scripting

Header and Footer...

Hi All, I need to write a script that In my file I have to check header and footer records are available or not. If it is available I have to run the script, otherwise I should not. But current script it is checking only the data inside the script. It is avoiding to check Header and Footer... (1 Reply)
Discussion started by: suresh_target
1 Replies

7. Shell Programming and Scripting

Copying the Header & footer Information to the Outfile.

Hi I am writing a perl script which checks for the specific column values from a file and writes to the OUT file. So the feed file has a header information and footer information. I header information isaround107 lines i.e. Starts with START-OF-FILE ....... so on .... ... (11 Replies)
Discussion started by: filter
11 Replies

8. UNIX for Dummies Questions & Answers

Help with the Header and Footer check

Hi, I need to check whether the incoming file has a header and footer using a UNIX script. The pattern of the header and footer is fixed as follows: Header: Name,Date Footer: Count, Total Name,Date ------------------------- ------------------------- ------------------------- Count,... (5 Replies)
Discussion started by: Sunny_teotia
5 Replies

9. Shell Programming and Scripting

How to add header and footer?

Hi, Guys, I want add header and footer in a file. I can add footer using following command: echo "Footer" >>file. I don't know how to add header. Thanks in advance (4 Replies)
Discussion started by: ken002
4 Replies

10. Shell Programming and Scripting

Inserting Header and footer

Hi All, I have several txt files i need to enter specific header and footer (both are separate) to all these files how can i do this? plz help.. Regards, Raghav (4 Replies)
Discussion started by: digitalrg
4 Replies
Login or Register to Ask a Question