Sponsored Content
Top Forums Shell Programming and Scripting Finding the length of the longest column Post 302731171 by RudiC on Wednesday 14th of November 2012 11:00:00 AM
Old 11-14-2012
Try
Code:
awk '{for (i=1;i<=NF;i++) if (length($i)>max) max=length($i)} END{print max}' file

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the length of the longest line

Dear All, To find the length of the longest line from a file i have used wc -L which is giving the proper output... But the problem is AIX os does not support wc -L command. so is there any other way 2 to find out the length of the longest line using awk or sed ? Regards, Pankaj (1 Reply)
Discussion started by: panknil
1 Replies

2. Shell Programming and Scripting

Finding longest common substring among filenames

I will be performing a task on several directories, each containing a large number of files (2500+) that follow a regular naming convention: YYYY_MM_DD_XX.foo_bar.A.B.some_different_stuff.EXT What I would like to do is automatically discover the part of the filenames that are common to all... (1 Reply)
Discussion started by: cmcnorgan
1 Replies

3. Shell Programming and Scripting

Finding multiple column values and match in a fixed length file

Hi, I have a fixed length file where I need to verify the values of 3 different fields, where each field will have a different value. How can I do that in a single step. (6 Replies)
Discussion started by: naveen_sangam
6 Replies

4. UNIX for Dummies Questions & Answers

How to remove duplicated based on longest row & largest value in a column

Hii i have a file with data as shown below. Here i need to remove duplicates of the rows in such a way that it just checks for 2,3,4,5 column for duplicates.When deleting duplicates,retain largest row i.e with many columns with values should be selected.Then it must remove duplicates such that by... (11 Replies)
Discussion started by: reva
11 Replies

5. Shell Programming and Scripting

Finding longest line in a Record

Good Morning/Afternoon All, I am using the nawk utility in korn shell to find the longest field and display that result. My Data is as follows: The cat ran The elephant ran Milly ran too We all ran I have tried nawk '{ if (length($1) > len) len=length($1); print $1}' filename The... (5 Replies)
Discussion started by: SEinT
5 Replies

6. UNIX for Dummies Questions & Answers

Display all the words whose length is equal to the longest word in the text

Hi Guys, I was going some trial and error to see if I can find the longest word in a text. I was using Pipes because they are easier to use in this case. I was stuck on this for a while so I thought I'll get some help with it. I tried this code to separate all the words in a text in... (4 Replies)
Discussion started by: bawse.c
4 Replies

7. Shell Programming and Scripting

Longest length of string in array

I would be grateful if someone could help me. I am trying to write a .sh script in UNIX. I have the following code; User=john User=james User=ian User=martin for x in ${User} do print ${#x} done This produces the following output; 4 5 3 6 (12 Replies)
Discussion started by: mmab
12 Replies

8. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

9. Shell Programming and Scripting

awk uniq and longest string of a column as index

I met a challenge to filter ~70 millions of sequence rows and I want using awk with conditions: 1) longest string of each pattern in column 2, ignore any sub-string, as the index; 2) all the unique patterns after 1); 3) print the whole row; input: 1 ABCDEFGHI longest_sequence1 2 ABCDEFGH... (12 Replies)
Discussion started by: yifangt
12 Replies

10. Shell Programming and Scripting

wc -L giving incorrect length of longest line

Running below line gives 3957 as length of longest line in file 20121119_SRMNotes_init.dat awk ' { if ( length > 3950 ) { x = length } }END{ print x }' 20121119_SRMNotes_init.dat While wc -L 20121119_SRMNotes_init.dat gives output as 4329. Why is there a difference between these two commands.... (2 Replies)
Discussion started by: Satish Mantha
2 Replies
VecStat(3pm)						User Contributed Perl Documentation					      VecStat(3pm)

NAME
Math::VecStat - Some basic numeric stats on vectors SYNOPSIS
use Math::VecStat qw(max min maxabs minabs sum average); $max=max(@vector); $max=max(@vector); ($max,$imax)=max(@vector); ($max,$imax)=max(@vector); $min=min(@vector); $min=min(@vector); ($max,$imin)=min(@vector); ($max,$imin)=min(@vector); $max=maxabs(@vector); $max=maxabs(@vector); ($max,$imax)=maxabs(@vector); ($max,$imax)=maxabs(@vector); $min=minabs(@vector); $min=minabs(@vector); ($max,$imin)=minabs(@vector); ($max,$imin)=minabs(@vector); $sum=sum($v1,$v2,...); $sum=sum(@vector); $sum=sum(@vector); $average=average($v1,$v2,...); $av=average(@vector); $av=average(@vector); $ref=vecprod($scalar,@vector); $ok=ordered(@vector); $ok=ordered(@vector); $ref=sumbyelement(@vector1,@vector2); $ref=diffbyelement(@vector1,@vector2); $ok=allequal(@vector1,@vector2); $ref=convolute(@vector1,@vector2); DESCRIPTION
This package provides some basic statistics on numerical vectors. All the subroutines can take a reference to the vector to be operated on. In some cases a copy of the vector is acceptable, but is not recommended for efficiency. max(@vector), max(@vector) return the maximum value of given values or vector. In an array context returns the value and the index in the array where it occurs. min(@vector), min(@vector) return the minimum value of given values or vector, In an array context returns the value and the index in the array where it occurs. maxabs(@vector), maxabs(@vector) return the maximum value of absolute of the given values or vector. In an array context returns the value and the index in the array where it occurs. minabs(@vector), minabs(@vector) return the minimum value of the absolute of the given values or vector. In an array context returns the value and the index in the array where it occurs. sum($v1,$v2,...), sum(@vector), sum(@vector) return the sum of the given values or vector average($v1,$v2,..), average(@vector), average(@vector) return the average of the given values or vector vecprod($a,$v1,$v2,..), vecprod($a,@vector), vecprod( $a, @vector ) return a vector built by multiplying the scalar $a by each element of the @vector. ordered($v1,$v2,..), ordered(@vector), ordered(@vector) return nonzero iff the vector is nondecreasing with respect to its index. To be used like if( ordered( $lowBound, $value, $highBound ) ){ instead of the (slightly) more clumsy if( ($lowBound <= $value) && ($value <= $highBound) ) { sumbyelement( @array1, @array2 ), diffbyelement(@array1,@array2) return the element-by-element sum or difference of two identically-sized vectors. Given $s = sumbyelement( [10,20,30], [1,2,3] ); $d = diffbyelement( [10,20,30], [1,2,3] ); $s will be "[11,22,33]", $d will be "[9,18,27]". allequal( @array1, @array2 ) returns true if and only if the two arrays are numerically identical. convolute( @array1, @array2 ) return a reference to an array containing the element-by-element product of the two input arrays. I.e., $r = convolute( [1,2,3], [-1,2,1] ); returns a reference to [-1,4,3] median evaluates the median, i.e. an element which separates the population in two halves. It returns a reference to a list whose first element is the median value and the second element is the index of the median element in the original vector. $a = Math::VecStat::median( [9,8,7,6,5,4,3,2,1] ); returns the list reference [ 5, 4 ] i.e. the median value is 5 and it is found at position 4 of the original array. If there are several elements of the array having the median value, e.g. [1,3,3,3,5]. In this case we choose always the first element in the original vector which is a median. In the example, we return [3,1]. =back =head1 HISTORY $Log: VecStat.pm,v $ Revision 1.9 2003/04/20 00:49:00 spinellia@acm.org Perl 5.8 broke test 36, exposing inconsistency in C<median>. Fixed, thanks to david@jamesgang.com. Revision 1.8 2001/01/26 11:10:00 spinellia@acm.org Added function median. Fixed test, thanks to Andreas Marcel Riechert <riechert@pobox.com> Revision 1.7 2000/10/24 15:28:00 spinellia@acm.org Added functions allequal diffbyelement Created a reasonable test suite. Revision 1.6 2000/06/29 16:06:37 spinellia@acm.org Added functions vecprod, convolute, sumbyelement Revision 1.5 1997/02/26 17:20:37 willijar Added line before pod header so pod2man installs man page correctly Revision 1.4 1996/02/20 07:53:10 willijar Added ability to return index in array contex to max and min functions. Added minabs and maxabs functions. Thanks to Mark Borges <mdb@cdc.noaa.gov> for these suggestions. Revision 1.3 1996/01/06 11:03:30 willijar Fixed stupid bug that crept into looping in min and max functions Revision 1.2 1995/12/26 09:56:38 willijar Oops - removed xy data functions. Revision 1.1 1995/12/26 09:39:07 willijar Initial revision BUGS
Let me know. I welcome any appropriate additions for this package. AUTHORS
John A.R. Williams <J.A.R.Williams@aston.ac.uk> Andrea Spinelli <spinellia@acm.org> perl v5.12.4 2011-07-11 VecStat(3pm)
All times are GMT -4. The time now is 09:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy