Sponsored Content
Top Forums Shell Programming and Scripting Select a portion of file based on query Post 302092780 by mahendramahendr on Thursday 12th of October 2006 06:04:29 AM
Old 10-12-2006
Code:
#!/usr/bin/perl -w

$file="test.txt";

print "Enter search string : ";
$str=<STDIN>;
chomp $str;

open(FH,$file) || die "Unable to open $file : $!\n";

my $line;
my $strt_str=0;
my @arr=();
my $fnd = 0;

while ( $line = <FH> )
{
        chomp $line;

        if( $line =~ /^header/  ) {
                print join("\n",@arr)."\n" if $fnd == 1;
                @arr = ();
                $strt_str = 1;
                $fnd = 0;
        }

        push(@arr,$line) if( $strt_str == 1 );

        $fnd = 1 if ( $line =~ /$str/ );

        $strt_str = 0 if ( $line =~ /^footer/ );
}

print  join("\n",@arr)."\n";


Last edited by blowtorch; 10-12-2006 at 07:28 AM.. Reason: add code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk program to select a portion of a line

Hi all, I am new to awk programs.I have a file like this vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd... (3 Replies)
Discussion started by: anju
3 Replies

2. Shell Programming and Scripting

select a portion of a file into a CSV

How will i convert a file <LDATE>10-12-07</LDATE><LTIME>13:47:48.553</LTIME><LTEXT>name:anju;city:blore;ph:123</LTEXT> <LDATE>10-12-07</LDATE><LTIME>13:47:48.553</LTIME><LTEXT>name:anju;city:blore;ph:123</LTEXT>... (8 Replies)
Discussion started by: anju
8 Replies

3. UNIX for Dummies Questions & Answers

Reading from a file and passing the value to a select query

Hi all, Here is my problem. I want to read data from a file and pass the variable to a select query. I tried but it doesn't seem to work. Please advise. Example below. FileName='filekey.txt' while read LINE do var=$LINE print "For File key $var" ${ORACLE_HOME}/bin/sqlplus -s... (1 Reply)
Discussion started by: er_ashu
1 Replies

4. Shell Programming and Scripting

Redirecting sql select query result to txt file

Hi , I just found you while surfing for the string 'Redirecting sql select query output from within a shell script to txt file/excel file' Could you find time sending me the code for the above question? It'll be great help for me. I have a perl file that calls the sql file... (1 Reply)
Discussion started by: dolphin123
1 Replies

5. Shell Programming and Scripting

Redirecting sql select query result to txt file

Hi Yogesh, Lucky that i caught you online. Yeah i read about DBI and the WriteExcel module. But the server is not supporting these modules. It said..."Cannot locate DBI"..."Cannot locate Spreadsheet::WriteExcel" I tried creating a simple text file to get the query output, but the... (1 Reply)
Discussion started by: dolphin123
1 Replies

6. UNIX for Advanced & Expert Users

need to get a portion of entries in file based on a criteria --- Help please

All, Below is the file, what i need to do is take the text in between the /*-- and --*/ , i mean the jobs. Then i have grep for system name . If the job is there in system 1 i have to print to a file. Basically i want to take all the jobs that are in system1 to another file . because... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

7. Shell Programming and Scripting

redirecting oracle sqlplus select query into file

So, I would like to run differen select queries on multiple databases.. I made a script wich I thought to be called something like.. ./script.sh sql_file_name out.log or to enter select statement in a command line.. (aix) and I did created some shell script wich is not working.. it... (6 Replies)
Discussion started by: bongo
6 Replies

8. Shell Programming and Scripting

Rename portion of file based on another file

Hello, I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills. In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Discussion started by: anjulka
3 Replies

9. Shell Programming and Scripting

Select lines from a file based on a criteria

Hi I need to select lines from a txt file, I have got a line starting with ZMIO:MSISDN= and after a few line I have another line starting with 'MOBILE STATION ISDN NUMBER' and another one starting with 'VLR-ADDRESS' I need to copy these three lines as three different columns in a separate... (3 Replies)
Discussion started by: Tlcm sam
3 Replies

10. UNIX for Dummies Questions & Answers

Select last update data based on file name

Hi All, I need to remove all files except the most update data based on date on filename Input data_AIDS_20150312.txt data_AIDS_20150311.txt data_AIDS_20150411.txt data_AIDS_20140312.txt the most updated data is data_AIDS_20150411.txt, so I'll remove other files. My expected output... (3 Replies)
Discussion started by: radius
3 Replies
librrd(3)							      rrdtool								 librrd(3)

NAME
librrd - RRD library functions DESCRIPTION
librrd contains most of the functionality in RRDTool. The command line utilities and language bindings are often just wrappers around the code contained in librrd. This manual page documents the librrd API. NOTE: This document is a work in progress, and should be considered incomplete as long as this warning persists. For more information about the librrd functions, always consult the source code. CORE FUNCTIONS
rrd_dump_cb_r(char *filename, int opt_header, rrd_output_callback_t cb, void *user) In some situations it is necessary to get the output of "rrd_dump" without writing it to a file or the standard output. In such cases an application can ask rrd_dump_cb_r to call an user-defined function each time there is output to be stored somewhere. This can be used, to e.g. directly feed an XML parser with the dumped output or transfer the resulting string in memory. The arguments for rrd_dump_cb_r are the same as for rrd_dump_opt_r except that the output filename parameter is replaced by the user- defined callback function and an additional parameter for the callback function that is passed untouched, i.e. to store information about the callback state needed for the user-defined callback to function properly. Recent versions of rrd_dump_opt_r internally use this callback mechanism to write their output to the file provided by the user. size_t rrd_dump_opt_cb_fileout( const void *data, size_t len, void *user) { return fwrite(data, 1, len, (FILE *)user); } The associated call for rrd_dump_cb_r looks like res = rrd_dump_cb_r(filename, opt_header, rrd_dump_opt_cb_fileout, (void *)out_file); where the last parameter specifies the file handle rrd_dump_opt_cb_fileout should write to. There's no specific condition for the callback to detect when it is called for the first time, nor for the last time. If you require this for initialization and cleanup you should do those tasks before and after calling rrd_dump_cr_r respectively. UTILITY FUNCTIONS
rrd_random() Generates random numbers just like random(). This further ensures that the random number generator is seeded exactly once per process. rrd_add_ptr(void ***dest, size_t *dest_size, void *src) Dynamically resize the array pointed to by "dest". "dest_size" is a pointer to the current size of "dest". Upon successful realloc(), the "dest_size" is incremented by 1 and the "src" pointer is stored at the end of the new "dest". Returns 1 on success, 0 on failure. type **arr = NULL; type *elem = "whatever"; size_t arr_size = 0; if (!rrd_add_ptr(&arr, &arr_size, elem)) handle_failure(); rrd_add_strdup(char ***dest, size_t *dest_size, char *src) Like "rrd_add_ptr", except adds a "strdup" of the source string. char **arr = NULL; size_t arr_size = NULL; char *str = "example text"; if (!rrd_add_strdup(&arr, &arr_size, str)) handle_failure(); rrd_free_ptrs(void ***src, size_t *cnt) Free an array of pointers allocated by "rrd_add_ptr" or "rrd_add_strdup". Also frees the array pointer itself. On return, the source pointer will be NULL and the count will be zero. /* created as above */ rrd_free_ptrs(&arr, &arr_size); /* here, arr == NULL && arr_size == 0 */ rrd_mkdir_p(const char *pathname, mode_t mode) Create the directory named "pathname" including all of its parent directories (similar to "mkdir -p" on the command line - see mkdir(1) for more information). The argument "mode" specifies the permissions to use. It is modified by the process's "umask". See mkdir(2) for more details. The function returns 0 on success, a negative value else. In case of an error, "errno" is set accordingly. Aside from the errors documented in mkdir(2), the function may fail with the following errors: EINVAL "pathname" is "NULL" or the empty string. ENOMEM Insufficient memory was available. any error returned by stat(2) In contrast to mkdir(2), the function does not fail if "pathname" already exists and is a directory. AUTHOR
RRD Contributors <rrd-developers@lists.oetiker.ch> 1.4.7 2009-11-15 librrd(3)
All times are GMT -4. The time now is 01:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy