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 offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 January 2018, 3:18 PM EST
Location: Foxborough, MA
Posts: 8,204
Thanks: 231
Thanked 786 Times in 733 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: 23 January 2018, 11:13 AM EST
Posts: 9,020
Thanks: 389
Thanked 1,254 Times in 1,068 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 07:57 PM
how to convert columns to rows suresh3566 Shell Programming and Scripting 6 11-04-2008 08:20 AM
awk - reformating rows into columns jmd2004 Shell Programming and Scripting 1 08-14-2008 12:56 AM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 07:03 PM



All times are GMT -4. The time now is 05:57 PM.