Sponsored Content
Full Discussion: awk BEGIN problem
Top Forums Shell Programming and Scripting awk BEGIN problem Post 302345005 by cola on Tuesday 18th of August 2009 08:06:43 AM
Old 08-18-2009
awk BEGIN problem

Code:
awk 
'BEGIN { 
    print "line one\nline two\nline three" 
}'

After ./awktest.sh
Code:
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:        GNU long options:
    -f progfile        --file=progfile
    -F fs            --field-separator=fs
    -v var=val        --assign=var=val
    -m[fr] val
    -W compat        --compat
    -W copyleft        --copyleft
    -W copyright        --copyright
    -W dump-variables[=file]    --dump-variables[=file]
    -W exec=file        --exec=file
    -W gen-po        --gen-po
    -W help            --help
    -W lint[=fatal]        --lint[=fatal]
    -W lint-old        --lint-old
    -W non-decimal-data    --non-decimal-data
    -W profile[=file]    --profile[=file]
    -W posix        --posix
    -W re-interval        --re-interval
    -W source=program-text    --source=program-text
    -W traditional        --traditional
    -W usage        --usage
    -W use-lc-numeric    --use-lc-numeric
    -W version        --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
    gawk '{ sum += $1 }; END { print sum }' file
    gawk -F: '{ print $1 }' /etc/passwd
./awktest.sh: line 4: BEGIN { 
    print "line one\nline two\nline three" 
}: command not found

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Another question on awk - Begin statement

Hi, I've a question on awk. In English I want to: (a) open a file, (b) search through the file for records where length of field15 > 20 characters and (c) print out some fields in the record. I've written the following and it works OK. The trouble is this will ALWAYS write out the column... (5 Replies)
Discussion started by: eff_cee
5 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

awk BEGIN END and string matching problem

Hi, Contents of BBS-list file: foo foo foo awk ' BEGIN { print "Analysis of \"foo\"" } /foo/ { ++n } END { print "\"foo\" appears", n, "times." }' BBS-list Output: Analysis of "foo" "foo" appears 3 times. awk ' (3 Replies)
Discussion started by: cola
3 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
LINT(1) 						      General Commands Manual							   LINT(1)

NAME
lint - a C program verifier SYNOPSIS
lint [ -abchnpuvx ] file ... DESCRIPTION
Lint attempts to detect features of the C program files which are likely to be bugs, or non-portable, or wasteful. It also checks the type usage of the program more strictly than the compilers. Among the things which are currently found are unreachable statements, loops not entered at the top, automatic variables declared and not used, and logical expressions whose value is constant. Moreover, the usage of functions is checked to find functions which return values in some places and not in others, functions called with varying numbers of argu- ments, and functions whose values are not used. By default, it is assumed that all the files are to be loaded together; they are checked for mutual compatibility. Function definitions for certain libraries are available to lint; these libraries are referred to by a conventional name, such as `-lm', in the style of ld(1). Arguments ending in .ln are also treated as library files. To create lint libraries, use the -C option: lint -Cfoo files . . . where files are the C sources of library foo. The result is a file llib-lfoo.ln in the correct library format suitable for linting pro- grams using foo. Any number of the options in the following list may be used. The -D, -U, and -I options of cc(1) are also recognized as separate argu- ments. p Attempt to check portability to the IBM and GCOS dialects of C. h Apply a number of heuristic tests to attempt to intuit bugs, improve style, and reduce waste. b Report break statements that cannot be reached. (This is not the default because, unfortunately, most lex and many yacc outputs produce dozens of such comments.) v Suppress complaints about unused arguments in functions. x Report variables referred to by extern declarations, but never used. a Report assignments of long values to int variables. c Complain about casts which have questionable portability. u Do not complain about functions and variables used and not defined, or defined and not used (this is suitable for running lint on a subset of files out of a larger program). n Do not check compatibility against the standard library. z Do not complain about structures that are never defined (e.g. using a structure pointer without knowing its contents.). Exit(2) and other functions which do not return are not understood; this causes various lies. Certain conventional comments in the C source will change the behavior of lint: /*NOTREACHED*/ at appropriate points stops comments about unreachable code. /*VARARGSn*/ suppresses the usual checking for variable numbers of arguments in the following function declaration. The data types of the first n arguments are checked; a missing n is taken to be 0. /*NOSTRICT*/ shuts off strict type checking in the next expression. /*ARGSUSED*/ turns on the -v option for the next function. /*LINTLIBRARY*/ at the beginning of a file shuts off complaints about unused functions in this file. AUTHOR
S.C. Johnson. Lint library construction implemented by Edward Wang. FILES
/usr/libexec/lint/lint[12] programs /usr/share/lint/llib-lc.ln declarations for standard functions /usr/share/lint/llib-lc human readable version of above /usr/share/lint/llib-port.ln declarations for portable functions /usr/share/lint/llib-port human readable . . . llib-l*.ln library created with -C SEE ALSO
cc(1) S. C. Johnson, Lint, a C Program Checker BUGS
There are some things you just can't get lint to shut up about. /*NOSTRICT*/ is not implemented in the current version (alas). 4th Berkeley Distribution October 22, 1996 LINT(1)
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy