Print record count of a file using shell script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Print record count of a file using shell script

Shell Programming and Scripting


Tags
record count

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 02-20-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 20 October 2014, 11:35 AM EDT
Location: India
Posts: 1,830
Thanks: 25
Thanked 524 Times in 503 Posts

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

Sponsored Links
Closed Thread

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 06:21 AM.