Sponsored Content
Full Discussion: Doubts About awk, and Gawk
Top Forums UNIX for Dummies Questions & Answers Doubts About awk, and Gawk Post 302773401 by matius_88 on Wednesday 27th of February 2013 09:05:41 PM
Old 02-27-2013
Doubts About awk, and Gawk

well i have some doubts about the use of this commands:


my first doubt is to know if there is a way to execute a awk program from a file? (now i do copy paste, i copy the script of a notepad on the terminal and then i press enter, but i want to put this scripts in some folder and execute them)

another doubt i have is how can i say to awk for retrieving all the information beside certaing pattern for example i want to get all the SBL codes except SBL151

Code:
awk ' {
        for(i=1;i<=NF;i++) {
                if($i ~ /SBL/ && $i <> /SBL151/ )
                        a[$i]++;
        }
} END {
        for(i in a)
                print i, a[i];
}' file

is this code ok?

other doubt is if is possible to use a switch in my code i have something like

Code:
awk ' {
        for(i=1;i<=NF;i++) {
                if($i ~ /SBL/)
                        a[$i]++;
                 if($i ~ /DBL/)
                        c[$i]++;
                 if($i ~ /XSL/)
                        d[$i]++;
                 if($i ~ /NBL/)
                        e[$i]++;

        }
} END {
        for(i in a)
                print i, a[i];
}' file

i want to make something like a switch based of i value instead of making 4 ifs.



and my last doubt is recently download gawk 3.1.2(awk for windows) but i cant make it work, i go with the cmd to the bin folder and then i try to copy paste the script of awk in the cmd and press enter but a lot of error codes are displayed. i dont know how to use this program, any of you have used it?, whats the process to run a script?


thanks for all!!
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

awk,gawk in bat file

Hi. I'm trying to convert bat file into shell script. Bat file invokes awk file in one section: c:\upg\exe\gawk -f c:\upg\awk\gen_sae.awk -v OP=C:\\upg\\lod\\... ...c:\upg\ref\saaxi.ref c:\upg\log\SAAEPWO.log c:\upg\ref\saaepref.log First of all I issued unix2dos command on that awk file.... (0 Replies)
Discussion started by: andrej
0 Replies

3. Shell Programming and Scripting

awk, sed and a shell doubts

Hi, I have 3 doubts which I posted it here. Doubt 1: I have a file containing data: 22 -73 89 10 99 21 15 -77 23 63 -80 91 -22 65 28 97 I am trying to print the fields in the reverse order and replace every field by its absolute (positive) value (ie.) I am looking for output: 10... (8 Replies)
Discussion started by: royalibrahim
8 Replies

4. Shell Programming and Scripting

awk miscellaneous doubts

In this following command: awk 'BEGIN{ORS=""}1' what does '1' signifies that comes after closing curly brace '}' of awk? I guess, it does not mean 'first occurrence' because I verified that. And, pls tell me how to override or suppress awk's field variables like $1, $2.. by positional... (7 Replies)
Discussion started by: royalibrahim
7 Replies

5. Shell Programming and Scripting

Substitution using awk/gawk

Hello, I have a file containing lines such as: (1 104 (16) (17) (18) (102))$ (1 105 (16) (17) (19:21) (102))$ I would like to extract the numbers, only by using awk (or gawk). I do not want to use "sed" as it is very slow. For now my solution consists in... (2 Replies)
Discussion started by: jolecanard
2 Replies

6. Shell Programming and Scripting

Removing \n within a record (awk/gawk)

I am using a solution that was provided by a member: awk '{s=$0;if(length(s) < 700){getline; s=s " " $0}printf("%s\n",s)}' This scans through a file and removes '\n' within a record but not the record delimiter. However, there are instances where there are MULTIPLE instances of '\n'... (10 Replies)
Discussion started by: CKT_newbie88
10 Replies

7. Shell Programming and Scripting

Gawk / Awk Merge Lines based on Key

Hi Guys, After windows died on my netbook I installed Lubuntu and discovered Gawk about a month ago. After using Excel for 10+ years I'm amazed how quick and easily Gawk can process data but I'm stuck with a little problem merging data from multiple lines. I'm an SEO Consultant and provide... (9 Replies)
Discussion started by: Jamesfirst
9 Replies

8. Shell Programming and Scripting

awk (gawk) grep & columns

Hi, I'm working with gawk (on DOS) today. A goal is: find a string for-instance '123', cut a line in two columns and write second one. The problem is: command line works OK, awk file doesn't. But I would like to work with file because there are many strings to find. input: line command: awk... (4 Replies)
Discussion started by: frajer
4 Replies

9. Shell Programming and Scripting

Awk miscellaneous doubts

Hi, I am having the following doubts on awk. Please clarify for me. a) What does it mean? awk '$1=$1' and how does it change if I append FS="" to the above code? b) What if I use awk -vFS="\n" (i.e) setting (input) field separator to newline char, then what will be the value of $0,... (6 Replies)
Discussion started by: royalibrahim
6 Replies

10. Shell Programming and Scripting

This function (decode64) runs on gawk but not on busybox awk

Hello, I'm trying to figure out a way to use a decode64 function in an embedded system who has few utilities, including busybox. Right now have something like this (taken from "google base64-and-base85-encoding-awk-scripts" sorry, I'm not able to post urls yet) _decode64() { &&... (4 Replies)
Discussion started by: chilicuil
4 Replies
SLEEP(1)						    BSD General Commands Manual 						  SLEEP(1)

NAME
sleep -- suspend execution for an interval of time SYNOPSIS
sleep seconds DESCRIPTION
The sleep command suspends execution for a minimum of seconds. If the sleep command receives a signal, it takes the standard action. IMPLEMENTATION NOTES
The SIGALRM signal is not handled specially by this implementation. The sleep command will accept and honor a non-integer number of specified seconds (with a '.' character as a decimal point). This is a non- portable extension, and its use will nearly guarantee that a shell script will not execute properly on another system. EXIT STATUS
The sleep utility exits 0 on success, and >0 if an error occurs. EXAMPLES
To schedule the execution of a command for x number seconds later (with csh(1)): (sleep 1800; sh command_file >& errors)& This incantation would wait a half hour before running the script command_file. (See the at(1) utility.) To reiteratively run a command (with the csh(1)): while (1) if (! -r zzz.rawdata) then sleep 300 else foreach i (`ls *.rawdata`) sleep 70 awk -f collapse_data $i >> results end break endif end The scenario for a script such as this might be: a program currently running is taking longer than expected to process a series of files, and it would be nice to have another program start processing the files created by the first program as soon as it is finished (when zzz.rawdata is created). The script checks every five minutes for the file zzz.rawdata, when the file is found, then another portion processing is done courteously by sleeping for 70 seconds in between each awk job. SEE ALSO
nanosleep(2), sleep(3) STANDARDS
The sleep command is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. HISTORY
A sleep command appeared in Version 4 AT&T UNIX. BSD
April 18, 1994 BSD
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy