Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-15-2010, 01:07 PM   #1
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, 03:03 PM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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, 03:06 PM   #3
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 01:02 PM.

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