LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-07-2013, 01:49 PM   #1
SamyIllouze
LQ Newbie
 
Registered: Nov 2013
Posts: 2

Rep: Reputation: Disabled
What is this Shell/Awk command doing ?


Code:
APP_PORT=`${AWK} -F\" ' \
                       /org.apache.coyote.tomcat4.CoyoteConnector/ { 
                          getline
                          print $2
                       }' ${JBOSS_APP_CFG} 2>/dev/null`
Hi i am bit lost with all the layers of regexp and escape characters, so from the code i posted above i specialy want to understand what comes immediately after the F for field separator, so we want a quote so we escape it with the backslash but why is there no space after the -F ? and why is org.apache.coyote.tomcat4.CoyoteConnector placed between the single quote and what are the slashes that are surrounding it ?

Thanks
 
Old 11-07-2013, 02:07 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I don't understand what the getline is doing here, I would normally use that to 'capture' the output of a system command executed by awk

So, I'm going to ignore it here

Code:
awk -F\" '/org.apache.coyote.tomcat4.CoyoteConnector/{print $2}' ${JBOSS_APP_CFG} 2>/dev/null
-F\" # use " as field separator
/string/ # only consider lines that contain 'string'
{print $2} # print field 2
${JBOSS_APP_CFG} # the file you want to process
2>/dev/null # don't display errors ,, pointless if you ask me



further reading https://startpage.com/do/search?q=awk+manual

note , to confuse matters there are various versions of awk
gawk,nawk,mawk

gawk is arguably the 'most powerful' having a much richer feature set
 
1 members found this post helpful.
Old 11-07-2013, 02:17 PM   #3
SamyIllouze
LQ Newbie
 
Registered: Nov 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
I don't understand what the getline is doing here, I would normally use that to 'capture' the output of a system command executed by awk

So, I'm going to ignore it here

Code:
awk -F\" '/org.apache.coyote.tomcat4.CoyoteConnector/{print $2}' ${JBOSS_APP_CFG} 2>/dev/null
-F\" # use " as field separator
/string/ # only consider lines that contain 'string'
{print $2} # print field 2
${JBOSS_APP_CFG} # the file you want to process
2>/dev/null # don't display errors ,, pointless if you ask me



further reading https://startpage.com/do/search?q=awk+manual

note , to confuse matters there are various versions of awk
gawk,nawk,mawk

gawk is arguably the 'most powerful' having a much richer feature set
Thanks, i think the getLine is there so that displays the second filed of the line immediately after th eone containing the tomcat entry string. getLine gets on with the rest of the instruction unlike next.
 
Old 11-07-2013, 02:30 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
the getline does nothing here..
https://www.gnu.org/software/gawk/ma...e/Getline.html

and the 2>/dev/null is also pointless
unless ${JBOSS_APP_CFG} doesn’t exist
BUT that should be checked before executing the awk,


Edit, I take that back
I see what it is doing now, it is skipping the matched line and printing field 2 of the next line

Last edited by Firerat; 11-07-2013 at 02:34 PM.
 
  


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
[SOLVED] Generate shell command wit awk cristalp Programming 7 03-21-2012 05:28 AM
[bash][awk] command runs from shell, not from script JohnyDRipper Programming 2 03-09-2012 05:01 AM
Pass a shell variable to an AWK command chogall Programming 1 12-23-2010 10:12 AM
[SOLVED] Shell script using awk command gagou7 Linux - Newbie 6 11-05-2009 12:27 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM

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

All times are GMT -5. The time now is 05:23 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