Sponsored Content
Full Discussion: Read line from file randomly
Top Forums Shell Programming and Scripting Read line from file randomly Post 302182998 by McLan on Tuesday 8th of April 2008 03:16:00 AM
Old 04-08-2008
Read line from file randomly

I have data file with customer.dat, and this contains the
HTML Code:
customer names
>cat customer.dat
FirstName1 LastName1
FistName2 LastName1
FistName3 MiddleName3 LastName3
This file can contain areoun 100 customer names.

Quote:
My requirement is to get the customer complete name randomly, I want to use RANDOM to generate random number, and then I want to read the complete name from the customer.dat with line number that matches with the random number

Any idea how to read the file if the line number is specified?
Regards,
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

use awk to read randomly located columns in an excel file

Hi, I have an excel file that have a random count of columns/fields and what im trying to do is to only retrieve all the rows under 2 specific field headers. I can use the usually command for awk which is awk 'print{ $1 $2}' > output.txt, but the location of the 2 specific field headers is... (9 Replies)
Discussion started by: mdap
9 Replies

2. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

3. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

4. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

Get 20% of lines in File randomly

Hello, This is my code: nb_lignes=`wc -l $1 | cut -d " " -f1` for i in $(seq $nb_lignes) do m=`head $1 -n $i | tail -1` //command done Please how can i change it to get Get 20% of lines in File randomly to apply "command" on each line ? 20% or 40% or 60 % (it's a parameter) Thank you. (15 Replies)
Discussion started by: chercheur857
15 Replies

7. UNIX for Dummies Questions & Answers

Solaris server read and write randomly slow

Hi! It's been a week now that connections to my server are slow. I can transfer one file of 6 GB at 50 MB/s but with a folder of the same size with multiple files I go down to 4 MB/s. Also, browsing a folder with multiple files takes a lot more time for the files to show. The only thing I've... (9 Replies)
Discussion started by: Boogie
9 Replies

8. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

9. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

10. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies
Poet::Cache(3pm)					User Contributed Perl Documentation					  Poet::Cache(3pm)

NAME
Poet::Cache -- Poet caching with CHI SYNOPSIS
# In a conf file... cache: defaults: driver: Memcached servers: ["10.0.0.15:11211", "10.0.0.15:11212"] # In a script... use Poet::Script qw($cache); # In a module... use Poet qw($cache); # In a component... my $cache = $m->cache; # For an arbitrary namespace... my $cache = Poet::Cache->new(namespace => 'Some::Namespace') # then... my $customer = $cache->get($name); if ( !defined $customer ) { $customer = get_customer_from_db($name); $cache->set( $name, $customer, "10 minutes" ); } my $customer2 = $cache->compute($name2, "10 minutes", sub { get_customer_from_db($name2) }); DESCRIPTION
Poet::Cache is a subclass of CHI. CHI provides a unified caching API over a variety of storage backends, such as memory, plain files, memory mapped files, memcached, and DBI. Each package and Mason component uses its own CHI namespace so that caches remain separate. CONFIGURATION
The Poet configuration entry 'cache', if any, will be passed to Poet::Cache->config(). This can go in any Poet conf file, e.g. "local.cfg" or "global/cache.cfg". Here's a simple configuration that caches everything to files under "data/cache". This is also the default if no configuration is present. cache: defaults: driver: File root_dir: ${root}/data/cache Here's a more involved configuration that defines several "storage types" and assigns each namespace a storage type. cache: defaults: expires_variance: 0.2 storage: file: driver: File root_dir: ${root}/data/cache memcached: driver: Memcached servers: ["10.0.0.15:11211", "10.0.0.15:11212"] compress_threshold: 4096 namespace: /some/component: { storage: file, expires_in: 5min } /some/other/component: { storage: memcached, expires_in: 1h } Some::Library: { storage: memcached, expires_in: 10min } Given the configuration above, and the code package Some::Library; use Poet qw($cache); this $cache will be created with properties driver: Memcached servers: ["10.0.0.15:11211", "10.0.0.15:11212"] compress_threshold: 4096 expires_in: 10min USAGE
Obtaining cache handle o In a script (namespace will be 'main'): use Poet::Script qw($cache); o In a module "MyApp::Foo" (namespace will be 'MyApp::Foo'): use Poet qw($cache); o In a component "/foo/bar" (namespace will be '/foo/bar'): my $cache = $m->cache; o Manually for an arbitrary namespace: my $cache = Poet::Cache->new(namespace => 'Some::Namespace'); # or my $cache = MyApp::Cache->new(category => 'Some::Namespace'); Using cache handle my $customer = $cache->get($name); if ( !defined $customer ) { $customer = get_customer_from_db($name); $cache->set( $name, $customer, "10 minutes" ); } my $customer2 = $cache->compute($name2, "10 minutes", sub { get_customer_from_db($name2) }); See CHI and Mason::Plugin::Cache for more details. MODIFIABLE METHODS
These methods are not intended to be called externally, but may be useful to override or modify with method modifiers in subclasses. initialize_caching Called once when the Poet environment is initialized. By default, calls "__PACKAGE__->config" with the configuration entry 'cache'. SEE ALSO
Poet AUTHOR
Jonathan Swartz <swartz@pobox.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Jonathan Swartz. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-05 Poet::Cache(3pm)
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy