Visit Our UNIX and Linux User Community

[Solved] awk oddity

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] awk oddity
# 1  
Old 02-14-2014
[Solved] awk oddity

I have to apologize for my ignorance so this question is probably stupid.

How does awk process a file? Does it read from top of input file to end of file going line by line?

Yoda helped me create an awk script that helps me parse the named.conf file and output it into a .csv file but when entries below what its processing are commented out with // it breaks.

Since I don't want to have duplicate forum entries that script can be found here if you want to look at the script.

This forum post is trying to understand how awk processes and why it might fail to read text when entries below are commented out. It consistently does this throughout the entire named.conf so its consistent.
# 2  
Old 02-14-2014
I suggest you look up the difference between an awk comment # My awk commnet...
And a C++ inline/single_line comment // My single line C++ comment.

ANSI C only has /* Ansi C comment. */ IIRC...

Last edited by wisecracker; 02-14-2014 at 11:29 AM.. Reason: See above.
# 3  
Old 02-14-2014
Originally Posted by wisecracker
... ... ...
ANSI C only has /* Ansi C comment. */ IIRC...
Comments introduced by // were added in the 1999 revision of the C Standard. So, current C compilers accept both:
// Comment to end of line.

 *     Comment from slash star to next star slash.

as comments.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 02-14-2014
Try to ignore comment lines, e.g. by adding sth like /^\/\//{next} to the top of the awk script.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-16-2014
Thank You everyone for your posts. RudiC suggestion helped me greatly. Thank You!

I know that will take care of any comments that begin with

Anyway to also add a way to ignore the comments that begin with

Last edited by djzah; 02-16-2014 at 09:20 PM..
# 6  
Old 02-17-2014
Originally Posted by djzah
Anyway to also add a way to ignore the comments that begin with

The same way as RudiC already suggested:
Originally Posted by RudiC
by adding sth like [modification by bakunin:]/^#/{next}[mod ends] to the top of the awk script.
The hints we give are supposed to be read, tried out, understood, then modified and applied differently to serve a similar but different purpose. They are NOT MEANT to be followed blindly without thinking. If you are given "do procedure A" as an answer to "how can i achieve A" you should find out how that works and try "do procedure B" first, before asking "how can i achieve B". Chances are it will work if you have understood how A was achieved in first place.

I hope this helps.

# 7  
Old 02-17-2014
Understood. I did figure it out. I had to include all in the same line. I usually only ask for help when I'm failing with everything I try to figure it out. Awk has been most challenging for me. I learn best by seeing examples, especially being a beginner.
I apologize for my questions if they offended.... Seriously just trying to learn and can't find any good beginner doco/books

Previous Thread | Next Thread
Test Your Knowledge in Computers #533
Difficulty: Easy
A Boolean is type of variable that is used to hold a truth value, either true or false.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

System call oddity

Hi all, I'm trying to use bash to create a basic parser for some text, because basic grep/sed/awk have all my needs covered. So, I'm creating the chain of grep/sed I need and trying the execute that on the data I gather. The problem is, it's not working as it does when hardcoded. e.g. ... (3 Replies)
Discussion started by: beomagi
3 Replies

2. Solaris

Sort Oddity

All, I'm baffled by some sort behavior on SunOS 5.10 and looking for guidance. Running the command: sort -t'|' -k5,5 -k7,7 -k1,1 -k2,2 -k3,3 -k6,6 -k8,8 test Against the file "test": thirdA||||first||second|Data thirdB||||first||second| thirdC||||first||second|Data... (11 Replies)
Discussion started by: effigy
11 Replies

3. Programming

Java double subtraction oddity (not the usual rounding discrepancy)

I've been going through a java tutorial, and ran across some strangeness in this small example... class SqrRoot { public static void main(String args) { double num,sroot,rerr,resquare; for(num = 1.0; num < 100.0; num++) { sroot = Math.sqrt(num); ... (1 Reply)
Discussion started by: Trones
1 Replies

4. BSD

Cron Oddity

Our webserver is running FreeBSD, for the last few days we have been having an issue with our cronjobs/mysql server. Specifically we have jobs that execute php scripts to do various things to the website. When running these php scripts manually, via external browser, or lynx on the server, they... (8 Replies)
Discussion started by: mrfr0g
8 Replies

5. UNIX for Dummies Questions & Answers

TR squeeze oddity

I discovered that where 'tr -s' works as expected on grepped input, it appears to completely fail on dig results. I am not sure if this is because of some sort of non posix compliancy, or what. Here is what I did: The command below works as expected, squeezing all repeated spaces to a single... (3 Replies)
Discussion started by: bdmeyersc
3 Replies

6. AIX

AIX SAN configuration problems/oddity

Hi, I have a strange problem. we're trying to connect an IBM pseries, to a Brocade switch, for SAN acess, using a badged emulex card, (IBM FC6239) WE can configure the device to see the fabric. The only problem we have is that the Brocade sees the HBA as storage, and not as a HBA. We've zoned... (1 Reply)
Discussion started by: praxis22
1 Replies

7. UNIX for Dummies Questions & Answers

VSFTP oddity

I am using smartFTP client on my windows machine to connect to a linux box of mine (different location) to download some large files 100+meg. The linux box is running vsftp. After several minutes of downloading, the connection suddenly dies, and I cannot reconnect to the box via FTP using ANY... (7 Replies)
Discussion started by: Spetnik
7 Replies

8. UNIX for Dummies Questions & Answers

Su Password Oddity

Hello Forum, I am having an odd occurence. When i do a su in a terminal or console session, I am able get authenticated as superuser without using the full or correct root password. Anyone have any idea? -AJ (4 Replies)
Discussion started by: jacobsa
4 Replies

9. UNIX for Dummies Questions & Answers

Textual oddity

This is my first post!! I really hope this question hasn't been asked a thousand times before(I'll bet it has). Anyway, here it is. I am new to the UNIX world by the way so forgive my ignorance. OK, whenever I write code on my windows machine and then try to port it over to UNIX I always get... (3 Replies)
Discussion started by: Jubba
3 Replies

Featured Tech Videos