Sponsored Content
Top Forums Shell Programming and Scripting Another question on awk - Begin statement Post 65893 by Ygor on Thursday 10th of March 2005 12:49:00 AM
Old 03-10-2005
Use a flag...
Code:
awk -F, -v header="blah" '
   length($15) > 20 {
       if (flg==0) {
           print header
           flg = 1
        }
        print $1","$3","$15, ++n
    } 
    END {
        print "RECORD COUNT IS: " n
    }' $INPUTFILE > $TEXTFILE

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK not processing BEGIN directive

Hello I have the following awk script: BEGIN { {FS = " " } {print "\t\tIllegal Loggon Attempts on MAIL\n"} {"date" | getline d} {printf "\t %s\n",d } {print "Loggon Name\t\t\t Number of Attempts\n"} ... (2 Replies)
Discussion started by: mojoman
2 Replies

2. Shell Programming and Scripting

Alias to awk BEGIN statement

I'd like to define an alias to awk's begin statement since I use awk with different delimiters all the time and it is tiresome to type awk '{OFS="\t";FS="\t"}{BLAH BLAH}' every time. The problem is that bash won't let me make an alias with an open quote, which is necessary for the BEGIN alias to... (3 Replies)
Discussion started by: baconbasher
3 Replies

3. Shell Programming and Scripting

awk getting stuck after BEGIN

I am beginner in awk awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr=$1}{print arr}' In the above script, opnoise is a file, I am reading it into an array and then printing the value corresponding to index 20. Well this is not my real objective, but I have posted this example to describe... (1 Reply)
Discussion started by: akshaykr2
1 Replies

4. Shell Programming and Scripting

awk BEGIN problem

awk 'BEGIN { print "line one\nline two\nline three" }' After ./awktest.sh Usage: awk -f progfile file ... Usage: awk 'program' file ... POSIX options: GNU long options: -f progfile --file=progfile -F fs --field-separator=fs -v var=val ... (7 Replies)
Discussion started by: cola
7 Replies

5. Shell Programming and Scripting

Perl: Question about 'BEGIN'

Newbie question, not sure of the use of BEGIN when you can just have the enclosed code inserted before the remaining program which means that code will get executed first anyway? (2 Replies)
Discussion started by: stevensw
2 Replies

6. Shell Programming and Scripting

BEGIN and END format in awk

I'm new to awk, trying to understand the basics. I'm trying to reset the counter everytime the program gets a new file to check. I figured in the BEGIN part it would work, but it doesn't. #!/bin/awk -f BEGIN {counter=0} { sum=0 for ( i=1; i<=NF;... (1 Reply)
Discussion started by: guitarist684
1 Replies

7. UNIX for Dummies Questions & Answers

awk search with begin

Hi, I have written below script to begin if the line has n #!/bin/ksh /usr/xpg4/bin/awk {/ n / 'BEGIN {X = "01"; X = "02"; X = "03"; X = "04"; X = "05"; X = "06"; X = "07"; X = "08"; X ="09"; X = "10"; X = "11"; X = "12"; };} NR > 1 {print $1 "\t" $5 "," X "," $6 " " $7}'} input.txt |... (9 Replies)
Discussion started by: stew
9 Replies

8. Shell Programming and Scripting

Awk: BEGIN: prints nothing

My code fails to do anything if I've BEGIN block in it: Run the awk script as: awk -f ~/bin/sum_dupli_gene.awk make_gene_probe.txt #!/usr/bin/awk -f BEGIN { print ARGV #--loads of stuff } END{ #more stuff } (14 Replies)
Discussion started by: genome
14 Replies

9. UNIX for Beginners Questions & Answers

Awk: use variable defined in begin

Hi there, I'm working with file more than 400K lines, 60 columns. Column count is going to be multiple of 12: 60, 12, 72 or so. NF/12 gives me on how many iterations I've to do to check certain value. For example: 7, 14th if only 24 columns in file. 7th, 14th and 21st if 36 columns in... (6 Replies)
Discussion started by: genome
6 Replies

10. Shell Programming and Scripting

Usage of a variable in awk BEGIN

Hi, diffcount=`awk 'BEGIN { while ( getline < "/scripts/matt/text.server1.reference" ) { arr++ } } { if (!( $0 in arr ) ) { print } }' $TMPDIR/$(basename $0 .sh) | wc -l` if ]; then OK="OK - No change in the interfaces status" elif ]; then DIFF=`awk 'BEGIN {... (4 Replies)
Discussion started by: nms
4 Replies
Template::View(3)					User Contributed Perl Documentation					 Template::View(3)

NAME
Template::View - customised view of a template processing context SYNOPSIS
# define a view [% VIEW view # some standard args prefix => 'my_', suffix => '.tt2', notfound => 'no_such_file' ... # any other data title => 'My View title' other_item => 'Joe Random Data' ... %] # add new data definitions, via 'my' self reference [% my.author = "$abw.name <$abw.email>" %] [% my.copy = "&copy; Copyright 2000 $my.author" %] # define a local block [% BLOCK header %] This is the header block, title: [% title or my.title %] [% END %] [% END %] # access data items for view [% view.title %] [% view.other_item %] # access blocks directly ('include_naked' option, set by default) [% view.header %] [% view.header(title => 'New Title') %] # non-local templates have prefix/suffix attached [% view.footer %] # => [% INCLUDE my_footer.tt2 %] # more verbose form of block access [% view.include( 'header', title => 'The Header Title' ) %] [% view.include_header( title => 'The Header Title' ) %] # very short form of above ('include_naked' option, set by default) [% view.header( title => 'The Header Title' ) %] # non-local templates have prefix/suffix attached [% view.footer %] # => [% INCLUDE my_footer.tt2 %] # fallback on the 'notfound' template ('my_no_such_file.tt2') # if template not found [% view.include('missing') %] [% view.include_missing %] [% view.missing %] # print() includes a template relevant to argument type [% view.print("some text") %] # type=TEXT, template='text' [% BLOCK my_text.tt2 %] # 'text' with prefix/suffix Text: [% item %] [% END %] # now print() a hash ref, mapped to 'hash' template [% view.print(some_hash_ref) %] # type=HASH, template='hash' [% BLOCK my_hash.tt2 %] # 'hash' with prefix/suffix hash keys: [% item.keys.sort.join(', ') [% END %] # now print() a list ref, mapped to 'list' template [% view.print(my_list_ref) %] # type=ARRAY, template='list' [% BLOCK my_list.tt2 %] # 'list' with prefix/suffix list: [% item.join(', ') %] [% END %] # print() maps 'My::Object' to 'My_Object' [% view.print(myobj) %] [% BLOCK my_My_Object.tt2 %] [% item.this %], [% item.that %] [% END %] # update mapping table [% view.map.ARRAY = 'my_list_template' %] [% view.map.TEXT = 'my_text_block' %] # change prefix, suffix, item name, etc. [% view.prefix = 'your_' %] [% view.default = 'anyobj' %] ... DESCRIPTION
TODO METHODS
new($context, \%config) Creates a new Template::View presenting a custom view of the specified $context object. A reference to a hash array of configuration options may be passed as the second argument. prefix Prefix added to all template names. [% USE view(prefix => 'my_') %] [% view.view('foo', a => 20) %] # => my_foo suffix Suffix added to all template names. [% USE view(suffix => '.tt2') %] [% view.view('foo', a => 20) %] # => foo.tt2 map Hash array mapping reference types to template names. The print() method uses this to determine which template to use to present any particular item. The TEXT, HASH and ARRAY items default to 'test', 'hash' and 'list' appropriately. [% USE view(map => { ARRAY => 'my_list', HASH => 'your_hash', My::Foo => 'my_foo', } ) %] [% view.print(some_text) %] # => text [% view.print(a_list) %] # => my_list [% view.print(a_hash) %] # => your_hash [% view.print(a_foo) %] # => my_foo [% BLOCK text %] Text: [% item %] [% END %] [% BLOCK my_list %] list: [% item.join(', ') %] [% END %] [% BLOCK your_hash %] hash keys: [% item.keys.sort.join(', ') [% END %] [% BLOCK my_foo %] Foo: [% item.this %], [% item.that %] [% END %] method Name of a method which objects passed to print() may provide for presenting themselves to the view. If a specific map entry can't be found for an object reference and it supports the method (default: 'present') then the method will be called, passing the view as an argument. The object can then make callbacks against the view to present itself. package Foo; sub present { my ($self, $view) = @_; return "a regular view of a Foo "; } sub debug { my ($self, $view) = @_; return "a debug view of a Foo "; } In a template: [% USE view %] [% view.print(my_foo_object) %] # a regular view of a Foo [% USE view(method => 'debug') %] [% view.print(my_foo_object) %] # a debug view of a Foo default Default template to use if no specific map entry is found for an item. [% USE view(default => 'my_object') %] [% view.print(objref) %] # => my_object If no map entry or default is provided then the view will attempt to construct a template name from the object class, substituting any sequence of non-word characters to single underscores, e.g. # 'fubar' is an object of class Foo::Bar [% view.print(fubar) %] # => Foo_Bar Any current prefix and suffix will be added to both the default template name and any name constructed from the object class. notfound Fallback template to use if any other isn't found. item Name of the template variable to which the print() method assigns the current item. Defaults to 'item'. [% USE view %] [% BLOCK list %] [% item.join(', ') %] [% END %] [% view.print(a_list) %] [% USE view(item => 'thing') %] [% BLOCK list %] [% thing.join(', ') %] [% END %] [% view.print(a_list) %] view_prefix Prefix of methods which should be mapped to view() by AUTOLOAD. Defaults to 'view_'. [% USE view %] [% view.view_header() %] # => view('header') [% USE view(view_prefix => 'show_me_the_' %] [% view.show_me_the_header() %] # => view('header') view_naked Flag to indcate if any attempt should be made to map method names to template names where they don't match the view_prefix. Defaults to 0. [% USE view(view_naked => 1) %] [% view.header() %] # => view('header') print( $obj1, $obj2, ... \%config) TODO view( $template, \%vars, \%config ); TODO AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 2000-2007 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin perl v5.12.1 2009-05-20 Template::View(3)
All times are GMT -4. The time now is 09:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy