The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Count first column on the basis of two other columns kaustubh137 Shell Programming and Scripting 1 05-29-2008 09:54 AM
How to get the count only if two column matches? gobinath Shell Programming and Scripting 3 05-27-2008 05:01 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
How to count pattern in column ahjiefreak Shell Programming and Scripting 12 12-04-2007 07:53 PM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 08:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2004
gemini gemini is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 2
Max column count in a file

I have to send a file to mainframe and before sending it, I have to execute the quote command to set the record length.
Since the file is dynamic, I do not know what the maximum size of a line could be.

Currently, I use the following function to get the Max Column Count. Since I use "sed" it takes a long time for big files.

GetMaxCols()
{
MAX_COL_SIZE=0
for line in `cat $1 | sed "s! !~!g"`
do
COL_COUNT=`echo $line | wc -c`
if [ "$COL_COUNT" -gt "$MAX_COL_SIZE" ]; then
MAX_COL_SIZE=$COL_COUNT
fi
done
echo $MAX_COL_SIZE
}


Any better ways to achieve this goal ?

Thanks in advance.
  #2 (permalink)  
Old 08-24-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...

awk 'length>max{max=length}END{print max}' file1
  #3 (permalink)  
Old 08-24-2004
gemini gemini is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 2
Great. Worked fine.

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0