LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2013, 10:02 AM   #1
brgr88
Member
 
Registered: Apr 2006
Distribution: Slackware 14.2
Posts: 48

Rep: Reputation: 15
Comments embedded in a pipeline - do they draw on resources?


If I have comments embedded in line-continuations in a script with a pipeline, will they get processed for every record flowing through the pipeline?

For instance, I have a script:

#!/bin/sh
sed 'my_sed_program' input_file \
| awk '
#This is comment line 1.
#This is comment line 2.
#This is comment line N......
{ do_whatever }
'
exit 0


If my "input_file" is pretty large, will those multiple comments in my awk program be processed (and of course skipped) for every input line? Or are they "stripped" on the first pass through and not processed again for the duration of my process?

In other words, from a performance perspective, would it be better to have my imbedded comments outside of the pipeline?
 
Old 07-19-2013, 10:36 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.


The comments you have written here are actually awk comments, not shell comments. But in any case I'm almost certain that they are excluded during the initial parsing stage. It would be crazy to do it any other way, since the parser doesn't need them.

You might look it up in the gawk reference manual:

http://www.gnu.org/software/gawk/man...ode/index.html
 
1 members found this post helpful.
Old 07-19-2013, 10:56 AM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

I looked at the source code of GNU awk. David is right, comments are ignored by lexical analyzer which runs only once.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: eSecurity in the pipeline LXer Syndicated Linux News 0 01-18-2006 11:46 AM
noob Pipeline help. promero Programming 8 09-11-2005 03:42 PM
pipeline buffering jk3us Linux - Software 2 12-17-2004 07:52 PM
pipeline using rm verstapp Linux - General 3 03-08-2004 11:33 PM
Pipeline implementation in C jiahe Programming 1 02-02-2003 05:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration