04-19-2011
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 logic I am trying to implement is if the length of $1 is greater than my variable len then assign that value to len and if a larger value is found replace the previous value in len with that value and finally print the value in that variable.
By chance would I be better off with a for loop here?
Or a for with a nested if that that matter?
The latest idea I had was to put length($1) in an array, sort it from highest to lowest and simply print the first value in the array since it will always be the highest but that seems like a waste of resources.
Thanks in Advance for the assistance
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
HI,
I am pretty new to Unix scripting. I will need help in Finding a character in first line of a file or a set of files.
The scenario is as follows:
Lets consider a set of files which is having a character "ID"(without quotes) in the first line of each file.I need to find this character... (14 Replies)
Discussion started by: bsandeep_80
14 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
Hello everyone...
I need to find out, how to find longest line or possibly lines in several files which are arguments for script. The thing is, that I tried some possibilities before, but nothing worked correctly.
Example
when i use:
awk ' { if ( length > L ) { L=length ;s=$0 } }END{ print... (23 Replies)
Discussion started by: 1tempus1
23 Replies
5. Shell Programming and Scripting
Hi,
I have a input file with the following entries:
1one
2two
3three
1four
2five
3six
1seven
1eight
1nine
2ten
The output should be
1one
2two
3three
1four
2five
3six (2 Replies)
Discussion started by: supchand
2 Replies
6. Shell Programming and Scripting
Hi,
I have a input file with the following entries:
1one
2two
3three
1four
2five
3six
1seven
1eight
1nine
2ten
2eleven
2twelve
1thirteen
2fourteen
The output should be: (5 Replies)
Discussion started by: supchand
5 Replies
7. Shell Programming and Scripting
Hi ,
I have a scenario where i have to find the incorrect records in the file.
In our comma delimited file , we have the following to be taken care :
1) if there is new line character then we have to capture the current line and the next line as error record
Ex : In a comma... (8 Replies)
Discussion started by: ashwin3086
8 Replies
8. Shell Programming and Scripting
Hi,
I am trying to figure out how to get the length of the longest column in the entire file (because the length varies from one row to the other)
I was doing this at first to check how many fields I have for the first row:
awk '{print NF; exit}' file
Now, I can do this:
awk '{ if... (4 Replies)
Discussion started by: MIA651
4 Replies
9. Shell Programming and Scripting
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
10. Shell Programming and Scripting
Dear All,
I have getting data as follows, the second field signifies table name and last one is time stamp. I have return always latest record based on time stamp. Could you please help me ?
I/P
====
... (1 Reply)
Discussion started by: srikanth38
1 Replies
LEARN ABOUT CENTOS
hwloc_topology_cpubind_support
hwloc_topology_cpubind_support(3) Hardware Locality (hwloc) hwloc_topology_cpubind_support(3)
NAME
hwloc_topology_cpubind_support -
SYNOPSIS
#include <hwloc.h>
Data Fields
unsigned char set_thisproc_cpubind
unsigned char get_thisproc_cpubind
unsigned char set_proc_cpubind
unsigned char get_proc_cpubind
unsigned char set_thisthread_cpubind
unsigned char get_thisthread_cpubind
unsigned char set_thread_cpubind
unsigned char get_thread_cpubind
unsigned char get_thisproc_last_cpu_location
unsigned char get_proc_last_cpu_location
unsigned char get_thisthread_last_cpu_location
Detailed Description
Flags describing actual PU binding support for this topology.
Field Documentation
unsigned char hwloc_topology_cpubind_support::get_proc_cpubind
Getting the binding of a whole given process is supported.
unsigned char hwloc_topology_cpubind_support::get_proc_last_cpu_location
Getting the last processors where a whole process ran is supported
unsigned char hwloc_topology_cpubind_support::get_thisproc_cpubind
Getting the binding of the whole current process is supported.
unsigned char hwloc_topology_cpubind_support::get_thisproc_last_cpu_location
Getting the last processors where the whole current process ran is supported
unsigned char hwloc_topology_cpubind_support::get_thisthread_cpubind
Getting the binding of the current thread only is supported.
unsigned char hwloc_topology_cpubind_support::get_thisthread_last_cpu_location
Getting the last processors where the current thread ran is supported
unsigned char hwloc_topology_cpubind_support::get_thread_cpubind
Getting the binding of a given thread only is supported.
unsigned char hwloc_topology_cpubind_support::set_proc_cpubind
Binding a whole given process is supported.
unsigned char hwloc_topology_cpubind_support::set_thisproc_cpubind
Binding the whole current process is supported.
unsigned char hwloc_topology_cpubind_support::set_thisthread_cpubind
Binding the current thread only is supported.
unsigned char hwloc_topology_cpubind_support::set_thread_cpubind
Binding a given thread only is supported.
Author
Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.
Version 1.7 Sun Apr 7 2013 hwloc_topology_cpubind_support(3)