Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to get nth line from a file usuing commands Post 302240624 by radoulov on Friday 26th of September 2008 06:50:52 AM
Old 09-26-2008
Or:

Code:
sed '789!d;q' infile

A quick test:

Code:
$ time head -813000 alert_xxx.log | tail -1
Starting control autobackup

real    0m5.457s
user    0m1.110s
sys     0m6.710s
$ time sed '813000!d;q' alert_xxx.log
Starting control autobackup

real    0m0.721s
user    0m0.470s
sys     0m0.200s

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to quickly show Nth line from the file

Hi all, How can I quickly show Nth line from the huge file(at least more than 15GB)? I used the following script but seems slower. See 2717298 th line. head -2717298 data0802.dat | tail -1 Thank you very much (4 Replies)
Discussion started by: mr_bold
4 Replies

2. Shell Programming and Scripting

Reading a file after nth line

I know how to read a file line by line. But don't to how to skip to a line matching a criteria and then continue reading it till the end. This is a log file. The input is a timestamp. 1. Find the timestamp in the log file 2. Read the remaining lines one at a time till EOF. How can I do... (9 Replies)
Discussion started by: avinthm
9 Replies

3. Shell Programming and Scripting

how to find third(nth) word in all line from a file

For example i'm having the below contents in a file: expr is great when you want to split a string into just two parts. The .* also makes expr good for skipping a variable number of words when you don't know how many words a string will have. But expr is lousy for getting, say, the fourth word... (2 Replies)
Discussion started by: bangarukannan
2 Replies

4. Shell Programming and Scripting

How to start reading from the nth line till the last line of a file.

Hi, For my reuirement, I have to read a file from the 2nd line till the last line<EOF>. Say, I have a file as test.txt, which as a header record in the first line followed by records in rest of the lines. for i in `cat test.txt` { echo $i } While doing the above loop, I have read... (5 Replies)
Discussion started by: machomaddy
5 Replies

5. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

6. Shell Programming and Scripting

Get the nth word of mth line in a file

Hi.. May be a simple question but I just began to write unix scripts a week ago, for sorting some huge amount of experiment data, so I got no common sense about unix scripting and really need your helps... The situation is, I want to read the nth word of mth line in a file, and then store it... (3 Replies)
Discussion started by: freezelty
3 Replies

7. Shell Programming and Scripting

Read a file from the nth line on

I have a script which reads from a job file and executed the scripts in the job file in sequence. #! /bin/ksh set -x while read line do $line.ksh if # mail the team fi done <"$file" The job file will be like abcd efgh ijkl mnop qrst This is working fine. I need to add... (2 Replies)
Discussion started by: nw2unx123
2 Replies

8. Shell Programming and Scripting

Print nth line in a file

Bash/Oracle Linux 6.4 A basic requirement. How can I get nth line of a file printed ? Can I use grep in this case ? Example: In the below file, 12th line is "Kernel parameter check passed for rmem_max" . I just want the 12 line to be printed. # cat sometext.txt Kernel version check... (2 Replies)
Discussion started by: John K
2 Replies

9. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

10. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
POE::Component::Client::Ping(3pm)			User Contributed Perl Documentation			 POE::Component::Client::Ping(3pm)

NAME
POE::Component::Client::Ping - a non-blocking ICMP ping client SYNOPSIS
use POE qw(Component::Client::Ping); POE::Component::Client::Ping->spawn( Alias => "pingthing", # defaults to "pinger" Timeout => 10, # defaults to 1 second Retry => 3, # defaults to 1 attempt OneReply => 1, # defaults to disabled Parallelism => 64, # defaults to autodetect BufferSize => 65536, # defaults to undef AlwaysDecodeAddress => 1, # defaults to 0 ); sub some_event_handler { $kernel->post( "pingthing", # Post the request to the "pingthing" component. "ping", # Ask it to "ping" an address. "pong", # Have it post an answer as a "pong" event. $address, # This is the address we want to ping. $timeout, # Optional timeout. It overrides the default. $retry, # Optional retries. It overrides the default. ); } # This is the sub which is called when the session receives a "pong" # event. It handles responses from the Ping component. sub got_pong { my ($request, $response) = @_[ARG0, ARG1]; my ($req_address, $req_timeout, $req_time) = @$request; my ($resp_address, $roundtrip_time, $resp_time, $resp_ttl) = @$response; # The response address is defined if this is a response. if (defined $resp_address) { printf( "ping to %-15.15s at %10d. pong from %-15.15s in %6.3f s ", $req_address, $req_time, $resp_address, $roundtrip_time, ); return; } # Otherwise the timeout period has ended. printf( "ping to %-15.15s is done. ", $req_address, ); } or use POE::Component::Client::Ping ":const"; # Post an array ref as the callback to get data back to you $kernel->post("pinger", "ping", [ "pong", $user_data ]); # use the REQ_USER_ARGS constant to get to your data sub got_pong { my ($request, $response) = @_[ARG0, ARG1]; my $user_data = $request->[REQ_USER_ARGS]; ...; } DESCRIPTION
POE::Component::Client::Ping is non-blocking ICMP ping client. It lets several other sessions ping through it in parallel, and it lets them continue doing other things while they wait for responses. Ping client components are not proper objects. Instead of being created, as most objects are, they are "spawned" as separate sessions. To avoid confusion (and hopefully not cause other confusion), they must be spawned with a "spawn" method, not created anew with a "new" one. PoCo::Client::Ping's "spawn" method takes a few named parameters: Alias => $session_alias "Alias" sets the component's alias. It is the target of post() calls. See the synopsis. The alias defaults to "pinger". Socket => $raw_socket "Socket" allows developers to open an existing raw socket rather than letting the component attempt opening one itself. If omitted, the component will create its own raw socket. This is useful for people who would rather not perform a security audit on POE, since it allows them to create a raw socket in their own code and then run POE at reduced privileges. Timeout => $ping_timeout "Timeout" sets the default amount of time (in seconds) a Ping component will wait for a single ICMP echo reply before retrying. It is 1 by default. It is possible and meaningful to set the timeout to a fractional number of seconds. This default timeout is only used for ping requests that don't include their own timeouts. Retry => $ping_attempts "Retry" sets the default number of attempts a ping will be sent before it should be considered failed. It is 1 by default. OneReply => 0|1 Set "OneReply" to prevent the Ping component from waiting the full timeout period for replies. Normally the ICMP protocol allows for multiple replies to a single request, so it's proper to wait for late responses. This option disables the wait, ending the ping transaction at the first response. Any subsequent responses will be silently ignored. "OneReply" is disabled by default, and a single successful request will generate at least two responses. The first response is a successful ICMP ECHO REPLY event. The second is an undefined response event, signifying that the timeout period has ended. A ping request will generate exactly one reply when "OneReply" is enabled. This reply will represent either the first ICMP ECHO REPLY to arrive or that the timeout period has ended. Parallelism => $limit Parallelism sets POE::Component::Client::Ping's maximum number of simultaneous ICMP requests. Higher numbers speed up the processing of large host lists, up to the point where the operating system or network becomes oversaturated and begin to drop packets. The difference can be dramatic. A tuned Parallelism can enable responses down to 1ms, depending on the network, although it will take longer to get through the hosts list. Pinging 762 hosts at Parallelism=64 Starting to ping hosts. Pinged 10.0.0.25 - Response from 10.0.0.25 in 0.002s Pinged 10.0.0.200 - Response from 10.0.0.200 in 0.003s Pinged 10.0.0.201 - Response from 10.0.0.201 in 0.001s real 1m1.923s user 0m2.584s sys 0m0.207s Responses will take significantly longer with an untuned Parallelism, but the total run time will be quicker. Pinging 762 hosts at Parallelism=500 Starting to ping hosts. Pinged 10.0.0.25 - Response from 10.0.0.25 in 3.375s Pinged 10.0.0.200 - Response from 10.0.0.200 in 1.258s Pinged 10.0.0.201 - Response from 10.0.0.201 in 2.040s real 0m13.410s user 0m6.390s sys 0m0.290s Excessively high parallelism values may saturate the OS or network, resulting in few or no responses. Pinging 762 hosts at Parallelism=1000 Starting to ping hosts. real 0m20.520s user 0m7.896s sys 0m0.297s By default, POE::Component::Client::Ping will guess at an optimal Parallelism value based on the raw socket receive buffer size and the operating system's nominal ICMP packet size. The latter figure is 3000 octets for Linux and 100 octets for other systems. ICMP packets are generally under 90 bytes, but operating systems may use alternative numbers when calculating buffer capacities. The component tries to mimic calculations observed in the wild. When in doubt, experiment with different Parallelism values and use the one that works best. BufferSize => $bytes If set, then the size of the receive buffer of the raw socket will be modified to the given value. The default size of the receive buffer is operating system dependent. If the buffer cannot be set to the given value, a warning will be generated but the system will continue working. Note that if the buffer is set too small and too many ping replies arrive at the same time, then the operating system may discard the ping replies and mistakenly cause this component to believe the ping to have timed out. In this case, you will typically see discards being noted in the counters displayed by 'netstat -s'. Increased BufferSize values can expand the practical limit for Parallelism. AlwaysDecodeAddress => 0|1 If set, then any input addresses will always be looked up, even if the hostname happens to be only 4 characters in size. Ideally, you should be passing addresses in to the system to avoid slow hostname lookups, but if you must use hostnames and there is a possibility that you might have short hostnames, then you should set this. Payload => $bytes Sets the ICMP payload (data bytes). Otherwise the component generates 56 data bytes internally. Note that some firewalls will discard ICMP packets with nonstandard payload sizes. Sessions communicate asynchronously with the Client::Ping component. They post ping requests to it, and they receive pong events back. Requests are posted to the component's "ping" handler. They include the name of an event to post back, an address to ping, and an optional amount of time to wait for responses. The address may be a numeric dotted quad, a packed inet_aton address, or a host name. Host names are not recommended: they must be looked up for every ping request, and DNS lookups can be very slow. The optional timeout overrides the one set when "spawn" is called. Ping responses come with two array references: my ($request, $response) = @_[ARG0, ARG1]; $request contains information about the original request: my ( $req_address, $req_timeout, $req_time, $req_user_args, ) = @$request; $req_address This is the original request address. It matches the address posted along with the original "ping" request. It is useful along with $req_user_args for pairing requests with their corresponding responses. $req_timeout This is the original request timeout. It's either the one passed with the "ping" request or the default timeout set with "spawn". $req_time This is the time that the "ping" event was received by the Ping component. It is a real number based on the current system's time() epoch. $req_user_args This is a scalar containing arbitrary data that can be sent along with a request. It's often used to provide continuity between requests and their responses. $req_user_args may contain a reference to some larger data structure. To use it, replace the response event with an array reference in the original request. The array reference should contain two items: the actual response event and a scalar with the context data the program needs back. See the SYNOPSIS for an example. $response contains information about the ICMP ping response. There may be multiple responses for a single request. my ($response_address, $roundtrip_time, $reply_time, $reply_ttl) = @$response; $response_address This is the address that responded to the ICMP echo request. It may be different than $request_address, especially if the request was sent to a broadcast address. $response_address will be undefined if $request_timeout seconds have elapsed. This marks the end of responses for a given request. Programs can assume that no more responses will be sent for the request address. They may use this marker to initiate another ping request. $roundtrip_time This is the number of seconds that elapsed between the ICMP echo request's transmission and its corresponding response's receipt. It's a real number. This is purely the trip time and does *not* include any time spent queueing if the system's parallelism limit caused the ping transmission to be delayed. $reply_time This is the time when the ICMP echo response was received. It is a real number based on the current system's time() epoch. $reply_ttl This is the ttl for the echo response packet we received. If the ":const" tagset is imported the following constants will be exported: REQ_ADDRESS, REQ_TIMEOUT, REQ_TIME REQ_USER_ARGS, RES_ADDRESS, RES_ROUNDTRIP, RES_TIME, RES_TTL SEE ALSO
This component's ICMP ping code was lifted from Net::Ping, which is an excellent module when you only need to ping one host at a time. See POE, of course, which includes a lot of documentation about how POE works. Also see the test program, t/01_ping.t, in the component's distribution. BUG TRACKER
https://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-Ping REPOSITORY
http://github.com/rcaputo/poe-component-client-ping/ OTHER RESOURCES
http://search.cpan.org/dist/POE-Component-Client-Ping/ AUTHOR &; COPYRIGHTS POE::Component::Client::Ping is Copyright 1999-2009 by Rocco Caputo. All rights are reserved. POE::Component::Client::Ping is free software; you may redistribute it and/or modify it under the same terms as Perl itself. You can learn more about POE at http://poe.perl.org/ perl v5.14.2 2012-03-07 POE::Component::Client::Ping(3pm)
All times are GMT -4. The time now is 09:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy