Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Print record count of a file using shell script

Shell Programming and Scripting


Tags
record count

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-20-2013
mmeda mmeda is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 20 February 2013, 5:23 AM EST
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 Unix and Linux 02-20-2013
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 27 April 2015, 3:11 AM EDT
Location: India
Posts: 1,878
Thanks: 27
Thanked 538 Times in 515 Posts

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

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 06:32 AM.