awk basics


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk basics
# 1  
Old 07-04-2006
Error awk basics

what is wrong with the code below;
it starts ,then does nothing, (even it doesn't end)

#!/bin/awk
x=1
b="foo"
awk printf("%s got a %d on the last test\n","Jim",83)
myout=("%s-%d",b,x)
print myout
# 2  
Old 07-04-2006
Quote:
Originally Posted by gfhgfnhhn
what is wrong with the code below;
it starts ,then does nothing, (even it doesn't end)

#!/bin/awk
x=1
b="foo"
awk printf("%s got a %d on the last test\n","Jim",83)
myout=("%s-%d",b,x)
print myout
awk is awaiting input from a file or command line. If you want to run it without having to enter the input, try:

BEGIN{
a=1;
b="foo";
printf("%s got a %d on the last test\n","Jim",83)
myout="%s %d \n";
printf myout,b,a;
}
_______________________________________________________________________
else try:
{
a=1;
b="foo";
printf("%s got a %d on the last test\n","Jim",83)
myout="%s %d \n";
printf myout,b,a;
}'
"hello"
To end it type ^D. Pressing enter continues printing the output.
# 3  
Old 07-04-2006
unfortunately it doesnt work correctly
although i made the modifications that you told
# 4  
Old 07-04-2006
what mesaage are you getting? Could you paste the code you ran?
Also, which OS and version of awk are you using?
# 5  
Old 07-04-2006
#!/bin/awk
BEGIN{
a=1;
b="foo";
printf("%s got a %d on the last test\n","Jim",83)
myout="%s %d \n";
printf myout,b,a;
}

********************************
********************************
#!/bin/awk
{
a=1;
b="foo";
printf("%s got a %d on the last test\n","Jim",83)
myout="%s %d \n";
printf myout,b,a;
}'


i tried both of the code above, my OS is OSF1,
i dont know the version of awk (how can i learn?)

i dont get any messages, the scripts starts, and does nothing
# 6  
Old 07-04-2006
Hi,

There are different versions(flavors) of awk like gawk, nawk etc. In Linux awk is actually a link to gawk which provides some extra capability. I have no idea about OSF1. When i try and execute the file using ./filename it doesn't works. So, i excute the file by awk -f <filename>. It executes fine if the code has "BEGIN" construct.
If i execute the code without BEGIN
{
a=1;
b="foo";
printf("%s got a %d on the last test\n","Jim",83)
myout="%s %d \n";
printf myout,b,a;
}
it waits for input or filename. So, i type "hello" and press enter. It displays the output and keeps on doing so pressing enter until i press ^D. ^D specifies end of file. awk's behavior is such that it executes the code for each line in the input file.

If the scripts starts for you, try typing any string and press enter. Does it comes up with the output message?
# 7  
Old 07-04-2006
yes everything works exactly as you have said.
thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX Basics

Hello, 1) I am trying to get involved in UNIX for educational purposes so I have installed the latest Ubuntu edition 12.04. Do you know another package that I could use it instead for educational purposes? 2)What is the difference between "~$" and "/$" (it comes with cd / and cd ~) .The... (1 Reply)
Discussion started by: Iwn
1 Replies

2. UNIX for Dummies Questions & Answers

help me with basics

hello everyone i have to start with unix as it is a part of my training programme and i have to do a self study, i dont know where to start from. i need some basic questions to be answerd like why we use unix ? what is a terminal? what is an editor? why we write commands inside terminal? these... (4 Replies)
Discussion started by: aryancool
4 Replies

3. AIX

AIX Basics

Hello , Everyone , I want to know the Aix Basics and how it works ,hardware related problems and solution etc. (1 Reply)
Discussion started by: narendram
1 Replies

4. UNIX for Dummies Questions & Answers

awk basics

Hi, Please tell me where can I get started with awk..like the basics and the whole awk stuff. Regards, Deepti (2 Replies)
Discussion started by: gaur.deepti
2 Replies

5. UNIX for Dummies Questions & Answers

awk basics and ebook request

Dear All, Could someone suggest a resource where I can start learning awk from scratch. I'm a biologist with little command line experience but I need some data analysis to be done. I've realised from reading forums and talking to bioinformaticians that awk is extremely powerful to perform... (1 Reply)
Discussion started by: pawannoel
1 Replies

6. Shell Programming and Scripting

Scripts and basics

Hi, I have a script which I need to modify the date "01/10/2008" and "31/10/2008" every month before running the report. Can I have some script to take the date automatically from the cal option. Hope it makes sense. Thanks in advance. (1 Reply)
Discussion started by: Jayanthsec
1 Replies

7. UNIX for Dummies Questions & Answers

Unix Basics

Hey, you said this forum was for Dummies, so don't blame me for the following! :D My whole "web building" life, I've had my sites hosted in one for or another. Lately, I've gotten into PHP and MySQL and, of course, those are also hosted for me. But lately, I've been thinking of using PHP and... (2 Replies)
Discussion started by: cap97
2 Replies
Login or Register to Ask a Question