Sponsored Content
Top Forums Shell Programming and Scripting Finding longest line in a Record Post 302515078 by matrixmadhan on Tuesday 19th of April 2011 02:10:45 AM
Old 04-19-2011
Quote:
Originally Posted by pravin27
Could this help you?
Code:
len=3
awk -v l=$len 'length($1)>l { l=length($1);rec=$0} END {print l," ", rec}' inputfile

Its not $1, its $0 - small change to what you have posted

Code:
awk -v l=0 'length($0)>l { l=length($0);rec=$0} END {print l," ", rec}' inputfile

This User Gave Thanks to matrixmadhan For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a character in first line of a record

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

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

3. 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

4. Shell Programming and Scripting

Bash script find longest line/lines in several files

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

Reject the record if the record in the next line does not satisfy the pattern

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

Reject the record if the record in the next line does not begin with 2.

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

finding the incorrect record

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

Finding the length of the longest column

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

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

10. Shell Programming and Scripting

Finding the Latest record

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
SoNotList(3)							       Coin							      SoNotList(3)

NAME
SoNotList - The SoNotList class is a list of SoNotRec notification records. SYNOPSIS
#include <Inventor/misc/SoNotification.h> Public Member Functions SoNotList (void) SoNotList (const SoNotList *nl) void append (SoNotRec *const rec) void append (SoNotRec *const rec, SoField *const field) void append (SoNotRec *const rec, SoEngineOutput *const engineout) void setLastType (const SoNotRec::Type type) SoNotRec * getFirstRec (void) const SoNotRec * getLastRec (void) const SoNotRec * getFirstRecAtNode (void) const SoField * getLastField (void) const SoEngineOutput * getLastEngineOutput (void) const uint32_t getTimeStamp (void) const void print (FILE *const file=stdout) const Detailed Description The SoNotList class is a list of SoNotRec notification records. Constructor &; Destructor Documentation SoNotList::SoNotList (void) Initialize list. SoNotList::SoNotList (const SoNotList *nl) Copy constructor. Does a bitwise copy of the nl object (no duplication of list elements). Member Function Documentation void SoNotList::append (SoNotRec *constrec) Append rec notification source to the list. void SoNotList::append (SoNotRec *constrec, SoField *constfield) Append rec notification source to the list, setting field as the last field having been influenced by the notification process. void SoNotList::append (SoNotRec *constrec, SoEngineOutput *constengineout) Append rec notification source to the list, setting engineout as the last engine output field having been influenced by the notification process. void SoNotList::setLastType (const SoNotRec::Typetype) Set the type of the last notification record in the list. SoNotRec * SoNotList::getFirstRec (void) const Returns the first record in the list. SoNotRec * SoNotList::getLastRec (void) const Returns the last record in the list. SoNotRec * SoNotList::getFirstRecAtNode (void) const Returns the first record in the list which is derived from SoBase. SoField * SoNotList::getLastField (void) const Returns the last field touched by notification. SoEngineOutput * SoNotList::getLastEngineOutput (void) const Returns the last engine output field touched by notification. uint32_t SoNotList::getTimeStamp (void) const Returns the time stamp when the notification started. void SoNotList::print (FILE *constfile = stdout) const Dump contents of list from tail record and backwards. Only available if compiled with debug information on. Author Generated automatically by Doxygen for Coin from the source code. Version 3.1.3 Wed May 23 2012 SoNotList(3)
All times are GMT -4. The time now is 06:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy