Sponsored Content
Full Discussion: basic awk questions
Top Forums Shell Programming and Scripting basic awk questions Post 302552103 by guessingo on Thursday 1st of September 2011 03:38:13 PM
Old 09-01-2011
Thank you for your help and the tip on the book. I'll check it out. I googled around and found some intro pages. I have used a link awk in my scripts such as print a certain tab, but that is it.

the c=0, through me off since I couldn't figure out why it was done. It looks like its unnecessary.

There still one part that is unclear to me.

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?

-- your answer:
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.

-GP
1. This is odd to me. It looks like, i is basically an index value in an array correct. So when I set i=1, this is short hand for go to the first index value of the array and the array is broken up by the spaces in my data file. Or should I look at $i as some kind of de-ref (old C terminology. had some C when I was an undergrad). so 'i' is basically a pointer. Awk syntax is a little different than what I am used to.

2. awk seems pretty useful for parsing files. I need to parse a sql output file. I was going to use the standard unix READ LINE, but I think awk will be easier (if I can figure out how to do it. ). The ability to pipe a unix function such as grep (to go line by line) into awk to go across the same line is very useful. Its look setting up a nested loop, but with simpler syntax.

for i in loop ...
for j in loop


thank you for your help. Your response was great. I was worried that this would be hard to follow.
 

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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 09:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy