Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

# of rows and columns

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-02-2009   -   Original Discussion by kylle345
kylle345's Unix or Linux Image
kylle345 kylle345 is offline
Registered User
 
Join Date: May 2009
Last Activity: 1 October 2015, 2:42 PM EDT
Posts: 123
Thanks: 22
Thanked 0 Times in 0 Posts
# of rows and columns

Hi,

Does anyone know the command to know the # of rows and columns for a file?

thanks
Sponsored Links
    #2  
Old Unix and Linux 07-02-2009   -   Original Discussion by kylle345
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 20 April 2018, 12:20 PM EDT
Location: Foxborough, MA
Posts: 8,253
Thanks: 240
Thanked 811 Times in 757 Posts
depends on your 'file' (whatever it is) format.......
Sponsored Links
    #3  
Old Unix and Linux 07-02-2009   -   Original Discussion by kylle345
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 20 April 2018, 10:56 AM EDT
Posts: 9,056
Thanks: 396
Thanked 1,279 Times in 1,082 Posts
Hi.

There may be a better way, but...



Code:
awk 'NF > X { X = NF } END {print X, NR}' my_file

(assumung space as delimeter)

where X is the number of columns and NR is the number of records.

use awk -F to specify a delimeter if it's not a (white)space.
    #4  
Old Unix and Linux 07-02-2009   -   Original Discussion by kylle345
ghostdog74's Unix or Linux Image
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
Quote:
Originally Posted by kylle345 View Post
Hi,

Does anyone know the command to know the # of rows and columns for a file?

thanks
See here(example 9) for example (assuming space separated).
Sponsored Links
Closed

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
How to merge rows into columns ???? bogu0001 Shell Programming and Scripting 4 01-16-2009 06:57 PM
how to convert columns to rows suresh3566 Shell Programming and Scripting 6 11-04-2008 07:20 AM
awk - reformating rows into columns jmd2004 Shell Programming and Scripting 1 08-13-2008 11:56 PM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 06:03 PM



All times are GMT -4. The time now is 12:24 PM.