LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-15-2010, 12:07 PM   #1
ghantauke
Member
 
Registered: Nov 2010
Posts: 114

Rep: Reputation: 6
Nested awk


Is it possible to write it? If so how?

My file name is file.txt. The following code seems to display some output.
awk '{output=$1}
{awk '' file.txt}
{print output}
' file.txt

But the following code doesn't.
awk '{output=$1}
{awk '{}' file.txt}
{print output}
' file.txt

This is the error message i get.
awk: cmd. line:1: {awk {} file.txt}
awk: cmd. line:1: ^ syntax error
 
Old 11-15-2010, 02:03 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I'm sorry to disappoint you, but nested awk does not exist! The awk statement inside the awk program is interpreted as a variable name and since it has not been assigned before, it is a null variable which is interpreted as false. In other words it does absolutely nothing! Regarding the single quotes following awk in your first working example, they simply close the shell quotes and reopen it again, so that in the awk program they result as nothing. When you put the brackets between these quotes, it results obviously in a syntax error.

Maybe if you explain what are you trying to do, we may help. Moreover if you provide an example of the input file and the desired output, it will result more clear what you're trying to achieve.
 
Old 11-15-2010, 02:06 PM   #3
ghantauke
Member
 
Registered: Nov 2010
Posts: 114

Original Poster
Rep: Reputation: 6
I was just curious whether nested awks existed or not. I've figured out another way of doing my stuff. Thx for the reply anyway.
 
  


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] awk nested if, command liner patolfo Programming 37 05-14-2010 12:19 AM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 05:39 PM
Does awk support nested if? lawrence_lee_lee Linux - Software 2 11-16-2007 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:10 PM.

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