Gawk program not working in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk program not working in a script
# 1  
Old 03-23-2017
Gawk program not working in a script

I've written a very simple gawk program which runs when I execute it at the POSIX shell but the corresponding '.awk' script I wrote doesn't return
any data. I'm on an HP-UX running gawk version 3.1. (w/all the defaults)

(As you can probably guess I'm a newbie going through the manual and trying to execute the code samples).

I did write another script (advice.awk) and it works fine.

Code:
$cat find_li.awk
# searches file: mail-list looking for regexp "li" and reporting 2nd column
# (which is the phone number) if found
#! /usr/local/bin/gawk '/li/ { print $0 }' mail-list

$find_li.awk (this is the run of my script w/no results)
$



(Below is me running the commands in the script and it works fine)
Code:
$/usr/local/bin/gawk '/li/ { print $0 }' mail-list
Amelia 555-5553 amelia.zodiacusque@gmail.com F
Broderick 555-0542 broderick.aliquotiens@yahoo.com R
Julie 555-6699 julie.perscrutabor@skeeve.com F
Samuel 555-3430 samuel.lanceolis@shu.edu A



So - Why doesn't the script return any results?
(I did do the chmod +x find_li.awk)



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-23-2017 at 12:32 PM.. Reason: Added CODE tags.
# 2  
Old 03-23-2017
well, it's because you commented out the command in a script:
Code:
# searches file: mail-list looking for regexp "li" and reporting 2nd column
# (which is the phone number) if found
#! /usr/local/bin/gawk '/li/ { print $0 }' mail-list

I think you meant this:
Code:
#!/usr/local/bin/gawk -f
# searches file: mail-list looking for regexp "li" and reporting 2nd column
# (which is the phone number) if found
/li/ { print $0 }

and have it call as find_li.awk mail-list

Last edited by vgersh99; 03-23-2017 at 12:51 PM..
# 3  
Old 03-23-2017
Solved.

Thanks vgersh99. That solved it.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] Gawk + MYSQL script

Hello! I've got script to write. It should read databases (names, volumes) from table testdatabase and compares it to actually existing databases in /var/lib/mysql/. If there is no informations about database in table - we should see information "There is no declared informations about database... (1 Reply)
Discussion started by: Zimny
1 Replies

2. Shell Programming and Scripting

Help with gawk array, loop in tcsh script

Hi, I'm trying to break a large csv file into smaller files and use unique values for the file names. The shell script i'm using is tcsh and i'm after a gawk one-liner to get the desired outcome. To keep things simple I have the following example with the desired output. fruitlist.csv apples... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

3. Windows & DOS: Issues & Discussions

Gawk Script in Windows batch file - Help

Good morning all. I have been running into a problem running a simple gawk script that selects every third line from an input file and writes it to an output file. gawk "NR%3==0" FileIn > FileOut I am attempting to run this command from a batch file at the command line. I have several hundred... (6 Replies)
Discussion started by: 10000springs
6 Replies

4. Programming

need help with gawk script

hi i've already created this script. When I execute the script it takes the argument and compares it to the 3rd column of the script. What I was wondering if I could get some help with is. I want to add another column to the script and it will be the result of a set number for example, (2000 - 3rd... (3 Replies)
Discussion started by: gengar
3 Replies

5. Shell Programming and Scripting

Help with gawk script that aggregates ip address ranges

Howdy folks, perhaps someone can help me with this problem. My knowledge of awk is not the best... but I've managed to a certain degree and now I'm stuck. These are the steps and the format outputs, problem is written in red text after the STEP 2: STEP 1 Unformated text file (100+... (3 Replies)
Discussion started by: gustisok
3 Replies

6. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

7. Shell Programming and Scripting

find | gawk --- NOT WORKING

Hi every1:) I have a problem with find and Pipe to gawk. Find -name '*.txt' -> works fine.. Gives all the txt file under home directory and sub directories But when I use it like this (see below). Find -name '*.txt' | gawk -F '\t' "script" :confused: It doesn't work.... (22 Replies)
Discussion started by: Needhelp2
22 Replies

8. Shell Programming and Scripting

gawk script

Hey guys need your help with an gawk script... here's what I have so far gawk '^d/ {printf "%-20s %-10s %-10s %-10s %-4s%2s %5s\n",$9,$1,$3,$4,$6,$7,$8}' ls.kbr The file ls.kbr is a capture of 'ls-al' What I want gawk to do is: 1) Find only directories (this is working) 2) skip lines... (2 Replies)
Discussion started by: zoo591
2 Replies

9. UNIX for Dummies Questions & Answers

Calculating field using AWK, or GAWK script

Hello all, I'm totally new to UNIX/Linux but I'm taking a course in it at my local JC. My question: I have been tasked with writing a gawk script that will create a nicely formatted report. That part I've done ok on...however, the very last thing that must be done is a calculation of a... (4 Replies)
Discussion started by: Trellot
4 Replies

10. Shell Programming and Scripting

how to use variables and gawk in a script?

Hi, I want to define variables in a shell script and make gawk use them to make some operations Mfn = $(grep " 1 " $fitxer | gawk '{print $2}') Xfn = $(grep " 1 " $fitxer | gawk '{print $3}') Yfn = $(grep " 1 " $fitxer | gawk '{print $4}') Zfn = $(grep " 1 " $fitxer | gawk... (9 Replies)
Discussion started by: pau
9 Replies
Login or Register to Ask a Question