Sponsored Content
Full Discussion: basic awk questions
Top Forums Shell Programming and Scripting basic awk questions Post 302550099 by g.pi on Wednesday 24th of August 2011 04:00:16 PM
Old 08-24-2011
Let me try and answer your questions. If you are new to awk and would like to learn more, here is a good book that I can recommend: sed & awk, Second Edition - O'Reilly Media

Quote:
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:
I see no big reason to do this, in this case. A BEGIN block executes (as the name implies) right at the beginning, before anything else is done. All that it is doing is assigning a value to 0 to the var c - which is not even being used in your code.

Quote:
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?
The script is iterating (in the while loop) over each of the fields in the input that you pass to your script. So, $i the first time will refer to field 1 and $i the second time will refer to field 2 and so on - until NF, the total number of fields.

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

7. printf("\n\nPROMPT %s \n",$0);
short hand of the "then" part of conditional logic
You are correct. If one of the fields has a value of CREATE, it prints the whole line preceded by PROMPT. The %s argument to printf if a format specifier which tell it print the arg as string.

Quote:
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?
You are correct about the -o. The "\" is to indicate that the current statement continue on the next line - basically, it is an escape for the newline character.

Quote:
-o ( substr(f,length(f)-6,7) == "START" ) \
Bit unclear about this myself. It seems to be looking at the last 7 characters of the field f, but comparing it with the string START. I guess the intent is to see if the field ends with START.

Hope this helps!!

-GP
This User Gave Thanks to g.pi For This Post:
 

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
All times are GMT -4. The time now is 11:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy