Script to count number of rows - Page 2 | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Script to count number of rows

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #8  
Old 02-19-2014
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 27 August 2014, 3:28 PM EDT
Location: Amsterdam
Posts: 9,358
Thanks: 271
Thanked 2,335 Times in 2,096 Posts
Then try:

Code:
awk '$1~/M$/{print $1}' file* | sort -u | wc -l

Sponsored Links
    #9  
Old 02-20-2014
ssk250 ssk250 is offline
Registered User
 
Join Date: Dec 2013
Last Activity: 11 August 2014, 8:50 AM EDT
Posts: 18
Thanks: 3
Thanked 1 Time in 1 Post
Script to display the lines which contain M as the last letter in the column of a two column line

Hi Scrutinizer,

thanks for your script.

I just changed it a little bit to get my required output which is as below:

1) Script to display the lines which contain M as the last letter in the column of a two column line:


Code:
awk '$1~/M$/{print $1"\t"$2}' filename | sort -u


2) Script to display files and their space occupied in terms of MB in a descending order


Code:
du -h *|awk '$1~/M$/{print $1"\t"$2}'|sort -nr



Once again thanks for the reply....

have a nice time

Last edited by Scrutinizer; 02-20-2014 at 12:39 AM.. Reason: code tags
Sponsored Links
    #10  
Old 02-20-2014
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 August 2014, 3:50 PM EDT
Location: San Jose, CA, USA
Posts: 4,462
Thanks: 175
Thanked 1,499 Times in 1,271 Posts
Quote:
Originally Posted by ssk250 View Post
Hi Scrutinizer,

thanks for your script.

I just changed it a little bit to get my required output which is as below:

1) Script to display the lines which contain M as the last letter in the column of a two column line:


Code:
awk '$1~/M$/{print $1"\t"$2}' filename | sort -u


2) Script to display files and their space occupied in terms of MB in a descending order


Code:
du -h *|awk '$1~/M$/{print $1"\t"$2}'|sort -nr



Once again thanks for the reply....

have a nice time
Note that if the files in your list ever grow in to the gigabyte or terabyte ranges, the code above won't list them.

If files larger than 999M might be in your future, you might be better off with real numbers rather than the more human friendly output produced by the du utility's -h option?:

Code:
du *|awk '$1 >= 1048576 {print $1"\t"$2}'|sort -nr

The Following User Says Thank You to Don Cragun For This Useful Post:
rbatte1 (02-20-2014)
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
Extract and count number of Duplicate rows Arun Mishra Shell Programming and Scripting 5 03-08-2013 10:53 PM
Shell script to count unique rows in a CSV Nani369 Shell Programming and Scripting 4 10-19-2011 03:33 PM
count number of rows based on other column values itsme999 UNIX for Dummies Questions & Answers 3 08-29-2010 05:11 PM
how to add the number of row and count number of rows juelillo Shell Programming and Scripting 6 07-15-2010 08:52 AM
how to count number of rows and sum of column using awk pistachio UNIX for Dummies Questions & Answers 2 05-20-2010 12:55 AM



All times are GMT -4. The time now is 04:58 PM.