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 05-22-2011, 10:22 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
problem with sed


Hi,

I am just trying to run the following piece of awk code. But it doesn't print anything...

where I am doing wrong ?

Quote:
[root@moon]# more script
#!/bin/awk -f
BEGIN {

# Print the squares from 1 to 10 the first way

i=1;
while (i <= 10) {
printf "\nThe square of ", i, " is ", i*i;
i = i+1;
}

}
[root@moon]# ./script

The square of
The square of
The square of
The square of
The square of
The square of
The square of
The square of
The square of
The square of

Last edited by sang_froid; 05-22-2011 at 10:29 AM.
 
Old 05-22-2011, 10:25 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well firstly its an awk script and not sed!!

Secondly you need to lookup how to use printf, in general even though it is the same for this case.
 
Old 05-22-2011, 10:29 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Or change : printf "\nThe square of ", i, " is ", i*i; to print "The square of ", i, " is ", i*i;

Hope this helps.
 
Old 05-22-2011, 10:33 AM   #4
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
Got it fixed...


Quote:
Originally Posted by sang_froid View Post
Hi,

I am just trying to run the following piece of awk code. But it doesn't print anything...

where I am doing wrong ?
 
Old 05-22-2011, 10:47 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please mark as SOLVED.
 
Old 05-23-2011, 03:09 PM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Maybe to explain: printf needs some formatting place holders like %d to print the arguments in the supplied list. I.e.
Code:
printf "\nThe square of %d%s%d", i, " is ", i*i;
will do it too.
 
  


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] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 07:59 AM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 07:43 AM
problem with sed eradev Programming 34 05-05-2010 12:50 PM
a sed problem thanhVic Programming 5 03-02-2005 01:05 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

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

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