Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script help printf

39 views
Skip to first unread message

anidil.r...@gmail.com

unread,
Feb 4, 2013, 5:25:37 PM2/4/13
to
All

script :
#!/bin/ksh

printf "HEADING1 HEADING2 HEADING3 HEADING4"
printf "===================================="


loop ( some processing results 4 varibales for each iteration )
...


variable1
variable2
variable3
variable4

printf " the 4 variables"

done

here is what is what

if variable has string UPRD, it shoud go under HEADING1 always
if variable has string UHA , it should go under HEADING2 always
if variable has string V1PRD , it should go under HEADING3 always
if variable has string V1HA , it should go under HEADING4 always

How can I do it in korn shell script?

TIA

Janis Papanagnou

unread,
Feb 4, 2013, 6:02:36 PM2/4/13
to
On 04.02.2013 23:25, anidil.r...@amdocs.com wrote:

[Please don't multi-post!]

> [...]

Basic suggestions posted to comp.lang.awk.

Janis

Reinhard Skarbal

unread,
Feb 5, 2013, 12:48:27 PM2/5/13
to

"anidil.r...@amdocs.com" <anidil.r...@gmail.com> schrieb im
Newsbeitrag news:2985fad4-8113-48b5...@googlegroups.com...
Hi

printf in ksh is very similar to C or AWK.
I have no host with ksh, so yust from may brain :

printf "%s\n%s\n..." $vara $varb ...

But I think google for "ksh printf example" will give you some links.

Regards
Reinhard


Barry Margolin

unread,
Feb 5, 2013, 12:54:32 PM2/5/13
to
In article <kergld$bvk$1...@news.albasani.net>,
Where in the printf documentation would it say how to get variables in
different table columns depending on their contents? This isn't a
printf feature to begin with.

Despite the subject line, his question doesn't really seem to be about
printf, it's about conditional coding.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Jon LaBadie

unread,
Feb 5, 2013, 9:21:57 PM2/5/13
to
To make a columned output line up, I often use the same printf
format string in both the headings and the data.

printf "%9s %9s %9s %9s\n" "head1" "head2" "head3" "head4"
... # rest of heading stuff
var1= var2= var3= var4= # null out your data variables

... # do your loop processing to set var1 etc.
printf "%9s %9s %9s %9s\n" "$var1" "$var2" "$var3" "$var4"

Of course you should adjust the %9s in the example to suit your data.

0 new messages