Sponsored Content
Top Forums Shell Programming and Scripting Finding larg number and add one Post 302256601 by radoulov on Monday 10th of November 2008 08:01:53 AM
Old 11-10-2008
Code:
sort -nr input | 
  { 
    read
    printf "%d\n" $(($REPLY+1))
    }

But some shells do not support a standalone read, others the $(()) expansion,
so you'll need something like:

Code:
sort -rn input |
  {
    read x
    printf "%d\n" `expr "$x" + 1`
    }

Some recent shells support the following syntax too:

Code:
sort -nr input |
  { 
    read 
    printf "%d\n" $((++REPLY))
    }

With zsh you can write something like this:

Code:
x=${${(n)$(<input)}[-1]}; print $((++x))


Last edited by radoulov; 11-10-2008 at 09:11 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding biggest number

I think my script is working but i am trying to understand while I am tracing to see if it's realli working.. can somebody please comment.. also. is there different way to write this in shell? sh -x findbiggestnum 1 2 3 + big=0 + big=1 + big=2 + big=3 + echo 3 3 big=0 ... (3 Replies)
Discussion started by: hankooknara
3 Replies

2. Shell Programming and Scripting

Need help finding number of logins!

Let's say I am trying to find out how many times someone has logged into the machine. Use last to display all the different logins, several names pop up, some multiple times. All I have been able to figure out is the total number of logins, but I can't determine how to compare if $1(user name) is... (3 Replies)
Discussion started by: TiznaraN
3 Replies

3. Solaris

Finding port number !!

Hi all , I want know the port no on which a particular application is running. How to find that? Thanks in anticipation (11 Replies)
Discussion started by: kumarmani
11 Replies

4. Shell Programming and Scripting

finding the line number from a grep ?

Hi there does anybody know how i can get the line number from an entry or entries in a file ?? for example if i had a file test1 test2 test3 test1 and i needed to get the line numbers for all instances of test1 in that file with the answer being (1,4) Would anybody be able... (7 Replies)
Discussion started by: hcclnoodles
7 Replies

5. Shell Programming and Scripting

Finding the nice(ni) number with PID?

Hi, is there a command that takes the PID of a process and that only diplays it's ni number? I`m pretty sure it would require pipes but I tried a few things that ended up miserably... Since the ps command doesn't show the ni unless I do ps -o ni but then I can't find a way to search the right... (2 Replies)
Discussion started by: Yakuzan
2 Replies

6. Solaris

Finding server serial number

Hi All, I wnat to know how to find out the Server serial number in command prompt? I am using sneep command but it throughing unknown. Thanks and Regards, (8 Replies)
Discussion started by: lbreddy
8 Replies

7. Shell Programming and Scripting

finding the number of dtsessions

I am trying to find out the number of dtsessions. using the command wc -l $FILE_NAME it works fine But when I try to assign this value to some variable using the command set NUM_DT_SESSION=$(wc -l $FILE_NAME) it shows error Variable syntax find below the complete command... (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

8. Shell Programming and Scripting

Finding number of strings in List

I have a list of strings stored in $Lst Example set Lst = "John Fred Kate Paul" I want to return 4 in this case. (1 Reply)
Discussion started by: kristinu
1 Replies

9. UNIX for Dummies Questions & Answers

Help on finding a number

Hello, Here is my question. I have a file which contains the html values. I have to find the decimal number from it. It is tagged around >68.74<. Please help me on it.. alt='' ><\/td>\n\t\t<td align=\"right\" class='data_table_text data_table_conv_averages_text' \ style='padding-right:... (1 Reply)
Discussion started by: sathyaonnuix
1 Replies

10. Shell Programming and Scripting

Finding which is Running number

Hi All, I have a list of data in the listing file and I run row by row to process the record, but how to identify what is the current process line number ? Thanks. (2 Replies)
Discussion started by: ckwan
2 Replies
RARPD(8)						    BSD System Manager's Manual 						  RARPD(8)

NAME
rarpd -- Reverse ARP Daemon SYNOPSIS
rarpd [-adfl] [interface [...]] DESCRIPTION
rarpd services Reverse ARP requests on the Ethernet connected to interface. Upon receiving a request, rarpd maps the target hardware address to an IP address via its name, which must be present in both the ethers(5) and hosts(5) databases. If a host does not exist in both data- bases the translation cannot proceed and a reply will not be sent. In normal operation, rarpd forks a copy of itself and runs in the background. Anomalies and errors are reported via syslog(3). OPTIONS
-a Listen on all the Ethernets attached to the system. If '-a' is omitted, an interface must be specified. -d Run in debug mode, with all the output to stderr. This option implies the -f option. -f Run in the foreground. -l Log all requests to syslog. FILES
/etc/ethers /etc/hosts SEE ALSO
bpf(4) Finlayson, R., Mann, T., Mogul, J.C., and Theimer, M., A Reverse Address Resolution Protocol, RFC 903. AUTHORS
Craig Leres (leres@ee.lbl.gov) and Steven McCanne (mccanne@ee.lbl.gov). Lawrence Berkeley Laboratory, University of California, Berkeley, CA. BSD
October 17, 2002 BSD
All times are GMT -4. The time now is 04:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy