Sponsored Content
Top Forums Shell Programming and Scripting Longest length of string in array Post 302572265 by CarloM on Wednesday 9th of November 2011 12:30:46 PM
Old 11-09-2011
Just check for a larger value each time through the loop and then print it afterwards.
Code:
m=-1
for x in ${User[@]}
do
   if [ ${#x} -gt $m ]
   then
      m=${#x}
   fi
done
print $m

 

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

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

3. Shell Programming and Scripting

Find longest string and print it

Hello all, I need to find the longest string in a select field and print that field. I have tried a few different methods and I always end up one step from where I need to be. Methods thus far: nawk '{if (length($1) > long) long=length($1); if(length($1)==long) print $1}' The above... (6 Replies)
Discussion started by: SEinT
6 Replies

4. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

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

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

7. Shell Programming and Scripting

Array Length Reports as Having Length when it is Empty?

Hello All, I have this script that does stuff like "starting, stopping & restarting" a Daemon Process running on my machine... My main question is why in part of my code (which you will see below) does the Array Length (i.e. ${#PIDS} ) return "1" when I know the Array is empty..? Here is... (17 Replies)
Discussion started by: mrm5102
17 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

Parse the longest matching string

Hello experts, I am trying to unscramble a mixed signal into component signals. Let the list of known signals be $ cat tmplist DU DU4016 GFF GFF2010 GFF201019 G2115 G211 DU40 (1 Reply)
Discussion started by: senhia83
1 Replies
Data::Page(3)						User Contributed Perl Documentation					     Data::Page(3)

NAME
Data::Page - help when paging through sets of results SYNOPSIS
use Data::Page; my $page = Data::Page->new(); $page->total_entries($total_entries); $page->entries_per_page($entries_per_page); $page->current_page($current_page); print " First page: ", $page->first_page, " "; print " Last page: ", $page->last_page, " "; print "First entry on page: ", $page->first, " "; print " Last entry on page: ", $page->last, " "; DESCRIPTION
When searching through large amounts of data, it is often the case that a result set is returned that is larger than we want to display on one page. This results in wanting to page through various pages of data. The maths behind this is unfortunately fiddly, hence this module. The main concept is that you pass in the number of total entries, the number of entries per page, and the current page number. You can then call methods to find out how many pages of information there are, and what number the first and last entries on the current page really are. For example, say we wished to page through the integers from 1 to 100 with 20 entries per page. The first page would consist of 1-20, the second page from 21-40, the third page from 41-60, the fourth page from 61-80 and the fifth page from 81-100. This module would help you work this out. METHODS
new This is the constructor, which takes no arguments. my $page = Data::Page->new(); There is also an old, deprecated constructor, which currently takes two mandatory arguments, the total number of entries and the number of entries per page. It also optionally takes the current page number: my $page = Data::Page->new($total_entries, $entries_per_page, $current_page); total_entries This method get or sets the total number of entries: print "Entries:", $page->total_entries, " "; entries_per_page This method gets or sets the total number of entries per page (which defaults to 10): print "Per page:", $page->entries_per_page, " "; current_page This method gets or sets the current page number (which defaults to 1): print "Page: ", $page->current_page, " "; entries_on_this_page This methods returns the number of entries on the current page: print "There are ", $page->entries_on_this_page, " entries displayed "; first_page This method returns the first page. This is put in for reasons of symmetry with last_page, as it always returns 1: print "Pages range from: ", $page->first_page, " "; last_page This method returns the total number of pages of information: print "Pages range to: ", $page->last_page, " "; first This method returns the number of the first entry on the current page: print "Showing entries from: ", $page->first, " "; last This method returns the number of the last entry on the current page: print "Showing entries to: ", $page->last, " "; previous_page This method returns the previous page number, if one exists. Otherwise it returns undefined: if ($page->previous_page) { print "Previous page number: ", $page->previous_page, " "; } next_page This method returns the next page number, if one exists. Otherwise it returns undefined: if ($page->next_page) { print "Next page number: ", $page->next_page, " "; } splice This method takes in a listref, and returns only the values which are on the current page: @visible_holidays = $page->splice(@holidays); skipped This method is useful paging through data in a database using SQL LIMIT clauses. It is simply $page->first - 1: $sth = $dbh->prepare( q{SELECT * FROM table ORDER BY rec_date LIMIT ?, ?} ); $sth->execute($page->skipped, $page->entries_per_page); change_entries_per_page This method changes the number of entries per page and the current page number such that the first item on the current page will be present on the new page. $page->total_entries(50); $page->entries_per_page(20); $page->current_page(3); print $page->first; # 41 $page->change_entries_per_page(30); print $page->current_page; # 2 - the page that item 41 will show in NOTES
It has been said before that this code is "too simple" for CPAN, but I must disagree. I have seen people write this kind of code over and over again and they always get it wrong. Perhaps now they will spend more time getting the rest of their code right... SEE ALSO
Related modules which may be of interest: Data::Pageset, Data::Page::Tied, Data::SpreadPagination. AUTHOR
Based on code originally by Leo Lapworth, with many changes added by by Leon Brocard <acme@astray.com>. CONTRIBUTORS
James Laver (ELPENGUIN) COPYRIGHT
Copyright (C) 2000-9, Leon Brocard LICENSE
This module is free software; you can redistribute it or modify it under the same terms as Perl itself. perl v5.16.2 2013-08-25 Data::Page(3)
All times are GMT -4. The time now is 12:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy