Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 02-19-2014
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 2 September 2015, 5:39 PM EDT
Location: Amsterdam
Posts: 10,434
Thanks: 359
Thanked 2,769 Times in 2,475 Posts
Then try:

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

Sponsored Links
    #9  
Old Unix and Linux 02-20-2014
ssk250 ssk250 is offline
Registered User
 
Join Date: Dec 2013
Last Activity: 20 July 2015, 2:44 AM EDT
Posts: 36
Thanks: 34
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 Linux

Last edited by Scrutinizer; 02-20-2014 at 12:39 AM.. Reason: code tags
Sponsored Links
    #10  
Old Unix and Linux 02-20-2014
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 2 September 2015, 4:27 PM EDT
Location: San Jose, CA, USA
Posts: 7,080
Thanks: 299
Thanked 2,336 Times in 2,000 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 Linux
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 05:45 PM.