Newbie AWK Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newbie AWK Question
# 1  
Old 07-20-2009
Error Newbie AWK Question

$ awk -f awk1.awk

Where awk1.awk reads:

BEGIN {
printf ("Name = Smith, Richard" > "awk1" \n)
printf ("Name = Johnson, Waylan" > "awk1" \n)
printf ("Name = Brown, Pat" > "awk1" \n)
}


If I get rid of "\n", awk1 file gets created but all the names appear on one line. If I keep the "\n" I get an error saying syntex error

How can I create the file so that all the names appear on separate lines.

Thanks in advance ....

# 2  
Old 07-20-2009
You need to put the newline in the string you want to print or on a separate line.
This code
Code:
printf ("Name = Smith, Richard" > "awk1" \n)
printf ("Name = Johnson, Waylan" > "awk1" \n)
printf ("Name = Brown, Pat" > "awk1" \n)

Should Be
Code:
printf ("Name = Smith, Richard\n" > "awk1" )
printf ("Name = Johnson, Waylan\n" > "awk1" )
printf ("Name = Brown, Pat\n" > "awk1")

or
Code:
printf ("Name = Smith, Richard" > "awk1" )
printf ("\n")
printf ("Name = Johnson, Waylan" > "awk1" )
printf ("\n")
printf ("Name = Brown, Pat" > "awk1" )
printf ("\n")

# 3  
Old 07-20-2009
On the RH server I happen to be logged into, the parenthesis don't work. I have this:

Code:
$ cat test.awk
BEGIN {
printf "Name = Smith, Richard\n" > "awk1"
printf "Name = Johnson, Waylan\n" > "awk1"
printf "Name = Brown, Pat\n" > "awk1"
}

which, when run as 'awk -f test.awk' results in this:

Code:
$ cat awk1
Name = Smith, Richard
Name = Johnson, Waylan
Name = Brown, Pat

# 4  
Old 07-20-2009
Thanks, ALL -

The parenthesis didn't work for me either.

The problem is solved when I got rid of the parenthesis.

Thanks again ...

Last edited by ora_umair; 07-20-2009 at 07:24 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Newbie question

Hey. i am doing a lab work for shcool I am new to using the commands. This question is give to me. I do not no the length of file nor do i know the how many charterers they are in the question. Question below "Assume that you are NOT currently in your home directory. Enter a command to copy... (1 Reply)
Discussion started by: maniac173
1 Replies

2. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

3. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

4. Programming

Newbie question

Dear all, I have a question related to parallel programing and if you can give me some hints on how to deal with it, it would be really great. I would like to run a small application on a supercompter of 128 CPUs. Unfortunately, on this machine only jobs which require 32 CPUs are allowed to... (1 Reply)
Discussion started by: Eduard
1 Replies

5. UNIX for Dummies Questions & Answers

Newbie question?

What is the best way to learn UNIX on the web, with out buying books? any link would be much help. Thank you in advance, L (1 Reply)
Discussion started by: lsoria1
1 Replies

6. UNIX for Dummies Questions & Answers

newbie question

I am taking a db classes toward oracle 10g. I am taking unix as well . I need to know what is the best option for os . should I use linux fedora. or get a sun box and start learning from there. Thanks (6 Replies)
Discussion started by: xzyan
6 Replies

7. Shell Programming and Scripting

newbie question

hey all, I have repeatedly seen scripts containing the following syntax, grep "hello" $myfile >> $log 2>&1 can anyone explain exactly what "2>&1" mean? THANK YOU (4 Replies)
Discussion started by: mpang_
4 Replies

8. UNIX for Dummies Questions & Answers

Very new newbie question

sorry if im not asking inthe right spot but, how do you turn the beeping off every time you hit a key onthe keyboard. I tried the click -n but it told me it didnt recognize click any help would be greatly appreciated ( the beeping is not going over well in the surrounding cubicles) thank you... (4 Replies)
Discussion started by: Split100
4 Replies

9. Shell Programming and Scripting

Newbie question

Hello, I have text file while looks this test1 test2 test3 test4 test5 test6 and if I want to parse it and make new file which would like this test1 test2 test3 test4 test5 test6 How can I do this in korn shell script Thanks (9 Replies)
Discussion started by: peeyush_23
9 Replies

10. UNIX for Dummies Questions & Answers

Newbie Question...

Okay, I succesfully installed Redhat Linux 7.2 on my comp. I got some Linux drivers for my network card off the manufacturers site, but said driver is just some C source code. Does anybody have any idea what I do with it? Sorry for being vague... any help is greatly appreciated. (4 Replies)
Discussion started by: flopper
4 Replies
Login or Register to Ask a Question