Sponsored Content
Full Discussion: The meaning of %s in printf
Top Forums UNIX for Dummies Questions & Answers The meaning of %s in printf Post 302420063 by quirkasaurus on Monday 10th of May 2010 12:47:19 PM
Old 05-10-2010
Quote:
Originally Posted by cosmologist
I have this command like that has %s in it, I know %s calls a column, but I am not sure I understand which column (I mean for my case I can check the input file, but I want to know how is this %s used, how comes tha same symbo; gives different columns in one command line:

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

Each %s give a different column in the output:

Code:
grep 3a junk.all.dat | awk '$4<=157.951{print $1, $2, $3, $4, $5}' | wc -l >> fitnumb.dat
grep 7a junk.all.dat | awk '$4<=118.793{print $1, $2, $3, $4, $5}' | wc -l >> fitnumb.dat
grep 9a junk.all.dat | awk '$4<=133.435{print $1, $2, $3, $4, $5}' | wc -l >> fitnumb.dat

Any idea how this %s works?
OKay, so I grunched this thread other than the first few posts.
In there no one mentioned how this line here:

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

Is missing some arguments. At any rate... The %s are formatting strings that printf interprets to mean "print the associated argument as a string".

In this command, however, there are no arguments to printf.
On my system, this doesn't even work.

But making some modifications and attempting to stick with the original intent, I got this to work:

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

2159 -> date | awk -f a.awk
grep Mon junk.all.dat | awk '$4 <= May{print $1, $2, $3, $4, $5}' | wc -l >> fitnumb.dat

I'm probably late to the game -- but HTH.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

meaning of !*

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

7. 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

8. 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

9. 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

10. 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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 09:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy