Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-20-2013
Registered User
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Print record count of a file using shell script

HI,

I need to print the record count of a file using shell script.

If the record count of a file excluding header and trailer record if greater than zero then print 'Record count of a file is xxxx records'.

If the record count is zero print 'zero records'


Thanks
Mahendra
Sponsored Links
    #2  
Old 02-20-2013
balajesuri's Avatar
#! /bin/bash
 
Join Date: Apr 2009
Location: India
Posts: 1,566
Thanks: 14
Thanked 440 Times in 425 Posts

Code:
awk 'END{if (NR-2 == 0){print "Zero records"} else {print "Record count: " NR-2}}' file

Sponsored Links
Reply

Tags
record count

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script for searching a record,copy to a file and then delete it kumara2010 Shell Programming and Scripting 5 06-16-2010 10:33 AM
How to assign record count output of isql to a shell variable ? vikram3.r Shell Programming and Scripting 4 05-26-2010 10:37 AM
shell script to get the arrival count of file RSC1985 Shell Programming and Scripting 2 08-20-2009 04:49 AM
Record count of a csv file ajaykk Shell Programming and Scripting 5 07-17-2008 05:16 PM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 07:22 PM



All times are GMT -4. The time now is 09:21 AM.