Sponsored Content
Full Discussion: basic awk questions
Top Forums Shell Programming and Scripting basic awk questions Post 302550085 by guessingo on Wednesday 24th of August 2011 02:50:45 PM
Old 08-24-2011
basic awk questions

I find an script with awk sitting around. I went through some online manuals, but I can't figure out exactly how it works. I can't post the whole program. Not allowed.

This is the line that is confusing me. I get when else is in the script
Code:
grep -v "^REM " $1| grep -v "JUNK;" | awk -F" " 'BEGIN{c=0;} { i=1; while ( i <= NF ) { f=$i; if ( f == "YUCK" ) printf("\n\nPROMPT %s \n",$0);

1. grep -v search line ,but ignore REM and JUNK
2. pipe to awk -F. -F does parsing of one line at a time

questions:
3. 'BEGIN {c=0}
Why do that? I don't see a 'c' variable anywhere else. When I googled this, you seem to do something like this when you add:

'BEGIN{for(c=0;c<50;c++)

4. { i=1; while ( i <= NF )
This a loop. that runs until the end of the line.

5. { f=$i;
didn't they just set i=1, and then increment it.
if f=$i, shouldn't that be a number instead, it appears it is what is actually in that field?

6. if ( f == "CREATE" )
condifitional logic

7. printf("\n\nPROMPT %s \n",$0);
short hand of the "then" part of conditional logic

\n\n I think means skip to lines right?
-- PROMPT? Does the word PROMPT get written? I did not see PROMPT as a key word?
-- %s? I know that printf has alot of variables you can use for formats. I did not find one for %s. what does that mean? Does anyone have a link for all the formats that work with printf?
-- /n $0)
-- another new line
-- print the enter line?

so if there is a CREATE, then print the whole line right?

After that I have a series of additional if then conditions, but I get most of it.


8. I see a -o, is that an "or" ? This is from a new line.

if ( ( f == "HERE" ) \
-o ( f == "THERE" ) \

-- if here or there? right?
-- why do we need "\", I know that means continue on a new line ,but why is that necessary here?


9. here is something else I don't get:

-o ( substr(f,length(f)-6,7) == "START" ) \

part of an if with an or
-- i know what substr does
-- f, is the variable that is being searched.
-- next it is check the length of f
-- so substr from length(f)-6 to 7.
-- then checking to see if it equals start




but the c variable is not used anywhere else?
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

basic UNIX questions

Can somebody please tell me a little about UNIX OS. For instance, is it ideal for digital media or how easy is it to get help and support? (3 Replies)
Discussion started by: buk5d
3 Replies

2. UNIX for Dummies Questions & Answers

Basic SFTP questions

I'm trying to find out what all is involved with setting up SFTP? 1) Do Solaris machines come with a SFTP server and client already installed. 2) If so would I have to install SFTP clients on windows, if I want to transfer files to a Solaris box? 3) If SFTP doesn't come prepackaged would I... (1 Reply)
Discussion started by: JohnRodey
1 Replies

3. UNIX for Dummies Questions & Answers

Basic Unix Questions

OK, here's a question from a true UNIX newb: How does one make a 20 line file? I'm lost. :confused: OK, I figured it out. :D (0 Replies)
Discussion started by: Kitchen Zinc
0 Replies

4. UNIX for Dummies Questions & Answers

Some basic questions

Hi- Newbie here with some basic questions: 1) I can't get alias to work. I tried alias ll='ls -al', but it doesn't work. When just typing 'alias', the new definition doesn't appear. I'm in a bash shell -- is that the problem. I tried switching to csh, but that didn't seem to help. This... (5 Replies)
Discussion started by: Aworstell
5 Replies

5. UNIX for Dummies Questions & Answers

Basic security questions

Hey guys, I've seen this posted a few times when i searched but I kinda want to know the cleanest way of doing it. On Solaris 8 and Solaris 9 What is the best way to disable telnet ssh1 and remote root login premanently? I've seen posts that say edit /etc/services edit this edit that... (3 Replies)
Discussion started by: kingdbag
3 Replies

6. UNIX for Dummies Questions & Answers

Basic variable questions

when you see something like this export SOMEDATA=.:/somedir/files what does the ".:" mean? I think the the "." alone would mean current directory but the ":" together is kind of new to me. (6 Replies)
Discussion started by: NycUnxer
6 Replies

7. UNIX for Dummies Questions & Answers

hp-ux basic questions

I have multiple questions How to list or find only Nov month's files? How can I get state of process like running, stop, or sleep etc? How can I check dependences of processes? plz ans any if u can thx regards, Mazhar Hussain (3 Replies)
Discussion started by: mazhar99
3 Replies

8. Solaris

solaris 10 and a few basic questions

hello, first, I'm quite new to solaris. I've installed solaris 10 basic (item 4 on the install-menue). now I had to realize that I don't have any option for connecting the machine from remote. ssh isn't even installed although I've coosed 'yes' for remote access. no matter what solaris is... (10 Replies)
Discussion started by: fourty2
10 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 02:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy