The meaning of %s in printf


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers The meaning of %s in printf
# 8  
Old 05-07-2010
perhaps our own limited assistance stems from your including only a snippet of the overall use. Looks like it is an eval of contents grepped out of an input file, which might be of use in explaining things...

In any case, note the following application of the %s modifier:

Code:
printf "%s\n"     hello 
printf "%3.3sp\n" hello 
printf "%3.2s\n"  hello hello hello

# 9  
Old 05-07-2010
Ok, maybe my initial question was a little confusing so let me try to explain again:

I have this code:
Code:
{ name = $1 }
{ delchi = $2 }

{printf("grep %s junk.all.dat | awk '$4<=%s{print $1, $2, $3, $4, $5}' | wc -l >> fitnumb.dat\n", name, delchi)}

so the first %s will give the "name" which is defined as $1, that makes sense.
Now my problem is with the second %s... Looking at the code it seems that it will give delchi... which is $2... my question is where is this $2 ? It is not in the original junk.all.dat... I know that the output of grep %s junk.all.dat is taken for the next part which is the awk command, but where does it get delchi from...
Does the question make more sense now?
# 10  
Old 05-07-2010
This is very confusing.

The first arg is name and the second arg is delchi. You grep for name from junk.all.dat. The output is piped into awk where you compare the fourth field to "delchi" If the fourth field is less than or equal to delchi, you print the first five fields which is piped into word count where only the number of lines is output.

Did I get that right?

Last edited by bluescreen; 05-07-2010 at 04:36 PM..
# 11  
Old 05-07-2010
Quote:
Originally Posted by bluescreen
It doesn't seem like you will get the output from "delchi" at all. You would need a second "%s" for that var.

But this code works... I just don't understand it Smilie

---------- Post updated at 03:37 PM ---------- Previous update was at 03:32 PM ----------

Quote:
Originally Posted by bluescreen
This is very confusing.

The first arg is name and the second arg is delchi. You grep for name from junk.all.dat. The output is piped int o awk where you compare the fourth field to "delchi" If the fourth field is less than or equal to delchi, you print the first five fields which is piped into word count where only the number of lines is output.

Did I get that right?
Yes, That's right,,, and my question is where/what is delchi? Was it created in this code?
# 12  
Old 05-07-2010
Does delchi mean "Delta Chi" ? This may be a statistical algorithm.

So you are looking for the number of times a value in the fourth field is less than or equal to a given value. *scratches head*
# 13  
Old 05-07-2010
Quote:
Originally Posted by bluescreen
Does delchi mean "Delta Chi" ? This may be a statistical algorithm.

So you are looking for the number of times a value in the fourth field is less than or equal to a given value. *scratches head*

Oh!! Is delchi a predefined function here?!??!
Yes, actually that's what I am using the code for, statistics...
But I searched for help for the delchi function but I didn't find anything, that's why I am not sure if it's a predefined function...
# 14  
Old 05-07-2010
Quote:
Originally Posted by cosmologist
Oh!! Is delchi a predefined function here?!??!
Yes, actually that's what I am using the code for, statistics...
But I searched for help for the delchi function but I didn't find anything, that's why I am not sure if it's a predefined function...
No. In this example, delchi is a variable - not a function.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Meaning of $1^

Hello everyone, I'm looking for the meaning of this expression, as I don't understand it quite clearly : $1^ What do you think it could be? I thought either: - match lines starting with argument 1 but it should be ^$1 - turn line around : word becomes drow Thanks in advance for your... (4 Replies)
Discussion started by: bibelo
4 Replies

2. Shell Programming and Scripting

Meaning

Please let me know the meaning for the below statements in shell scripting. 1) exit -99 -------------------------------- 2) set prgdir = `pwd` set runFlag = runFlag:FALSE ------------------------------------- 3) if (-f $prgdir/maillst.eml) then set distEmail = `cat $prgdir/maillst.eml`... (1 Reply)
Discussion started by: lg123
1 Replies

3. UNIX for Dummies Questions & Answers

meaning of <<!

Hi all, I wanna know the meaning of the last word "<<! " sudo su - user <<! please help on this !!!! (1 Reply)
Discussion started by: sudharson
1 Replies

4. Shell Programming and Scripting

^$$ meaning

Hi , Can anyone please let me know whta the follwoing piece of code for ScriptName=${0##*/} if pgrep -f "$ScriptName" | grep -v "^$$\$" ; then echo `date`": Sctipt $ScritName is already runnig" exit fi Thnx a lot in advance Please use code tags when posting data and code... (8 Replies)
Discussion started by: Pratik4891
8 Replies

5. Shell Programming and Scripting

meaning of !*

can someone please tell what !* means in shell syntax. Regards, (3 Replies)
Discussion started by: busyboy
3 Replies

6. Shell Programming and Scripting

What is the meaning of $_

Hi, Can somebody tell the usage of "$_" cd $_ ? and ls $_ ? (4 Replies)
Discussion started by: giri_luck
4 Replies

7. UNIX for Dummies Questions & Answers

what the meaning of #*

can some one please tell the meaning of the second statement i.e n=${m#*=} i couldnt get the meaning of the #*= 1.) m="mohit=/c/main/issue" echo $m result ----------- mohit=/c/main/issue 2.) n=${m#*=} echo $n RESULT ------- /c/main/issue (1 Reply)
Discussion started by: narang.mohit
1 Replies

8. UNIX for Dummies Questions & Answers

Use and meaning of $*

Can someone explain the use and meaning of "$*" expression. (2 Replies)
Discussion started by: sinpeak
2 Replies

9. AIX

meaning of ${0%${0##*/}}

. ${0%${0##*/}}Script_Name if i issue this command, it is executing the script. can any one tell what is the meaning of ${0%${0##*/}} (7 Replies)
Discussion started by: nyelavarthy
7 Replies

10. Shell Programming and Scripting

what is the meaning here?

#!/bin/sh $ORACLE_HOME/bin/sqlplus -S $orauserid/$orapasswd@$oradb << _TMP alter session set nls_date_format = 'YYYYMMDD HH24:MI'; set linesize 100 set pagesize 400 ok the above is part of a script..i just wanna know what does sqlplus -S means?? as in why we need to insert the -S behind? (2 Replies)
Discussion started by: forevercalz
2 Replies
Login or Register to Ask a Question