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

👤 Login to reply

    #1  
Old 07-02-2009
kylle345 kylle345 is offline
Registered User
 
# 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 07-02-2009
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
depends on your 'file' (whatever it is) format.......
Sponsored Links
    #3  
Old 07-02-2009
Scott Scott is offline Forum Staff  
Administrator
 
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 07-02-2009
ghostdog74 ghostdog74 is offline
Registered User
 
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
👤 Login to reply

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
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 07:00 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?