Explanation for printf string in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Explanation for printf string in awk
# 1  
Old 03-02-2010
Explanation for printf string in awk

hi all
can any one help me to understand this
Code:
bdf -t vfxs | awk '/\//{printf("%-30s%-10s%-10s%-10s%-5s%-10s\n",$1,$2,$3,$4,$5,$6)}'

i want to understand the numbers %-30S%

Last edited by pludi; 03-02-2010 at 04:31 PM.. Reason: clarified title
# 2  
Old 03-02-2010
The percent sign starts a special format string for printf. A character (in this case 's') specifies what kind of data to print, which would be strings in your case. The -nn (eg. -30) is a width-specifier, which means that the string should be left-justified, and no more than 30 characters wide.

For more details see the man page for printf
# 3  
Old 03-02-2010
It just used to format the output .

For example ,
You are printing the string which has 25 characters.If you give %30s when print that string then you will get five space characters in front of the string.
If the string has more that 30characters you will not get the space characters .
# 4  
Old 03-02-2010
thanks alot
# 5  
Old 03-02-2010
man printf
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printf padded string

Is possible to print padded string in printf? Example echo 1 | awk '{printf("%03d\n", $1)}' 001I want S1 S11 S2 S21to be padded as: S01 S11 S02 S21Thanks! (26 Replies)
Discussion started by: yifangt
26 Replies

2. Shell Programming and Scripting

Unable to match string within awk printf

Hi All I am working to process txt file into csv commo separated. Input.txt 1,2,asdf,34sdsd,120,haahha2 2,2,wewedf,45sdsd,130,haahha ..... .... Errorcode.txt 120 130 140 myawk.awk code: { BEGIN{ HEADER="f1,f2,f3,f4,f5,f6" (4 Replies)
Discussion started by: krsnadasa
4 Replies

3. Shell Programming and Scripting

How to print a string using printf?

I want to print a string say "str1 str2 str3 str4" using printf. If I try printing it using printf it is printing as follows. output ------- str1 str2 str3 str4 btw I'm working in AIX. This is my first post in this forum :) regards, rakesh (4 Replies)
Discussion started by: enigmatrix
4 Replies

4. Shell Programming and Scripting

awk explanation

Hello, I have recently come across this awk program. Can some one shed some light on what is taking place. awk '{!a++}END{for(i in a) if ( a >10 ) print a,i }' $FILE Best Regards, jaysunn (1 Reply)
Discussion started by: jaysunn
1 Replies

5. Shell Programming and Scripting

String formatting using awk printf

Hi Friends, I am trying to insert lines of the below format in a file: # x3a4914 Joe 2010/04/07 # seh Lane 2010/04/07 # IN01379 Larry 2010/04/07 I am formatting the strings as follows using awk printf: awk 'printf "# %s %9s %18s\n", $2,$3,$4}' ... (2 Replies)
Discussion started by: sugan
2 Replies

6. Shell Programming and Scripting

Help formatting a string. Something like printf?

Hi I'm having a problem with converting a file: ID X 1 7 1 8 1 3 2 5 2 7 2 2 To something like this: ID X1 X2 X3 1 7 8 3 2 5 7 2 I've tried the following loop: for i in `cat tst.csv| awk -F "," '{print $1}'| uniq`;do grep -h $i... (4 Replies)
Discussion started by: flotsam
4 Replies

7. Shell Programming and Scripting

printf with Character String

I am trying to use printf with a character string that is used within a do loop. The problem is that while in the loop, the printf prints the variable name instead of the value. The do loop calls the variable name from a text file (called device.txt): while read device do cat $device.clean... (2 Replies)
Discussion started by: dleblanc67
2 Replies

8. Shell Programming and Scripting

awk printf formatting using string format specifier.

Hi all, My simple AWK code does C = A - B If C can be a negative number, how awk printf formating handles it using string format specifier. Thanks in advance Kanu :confused: (9 Replies)
Discussion started by: kanu_pathak
9 Replies

9. Shell Programming and Scripting

find: problems escaping printf-command string

Hi Folks! Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused: My shell script snippet looks like this: #!/bin/sh .. COMMAND="find ./* -printf '%p %m %s %u %g \n'" echo "Command: ${COMMAND}"... (1 Reply)
Discussion started by: grahamb
1 Replies

10. Shell Programming and Scripting

AWK explanation

Hi, Could anyone please explain why we have arr=1 - what does this statement do? awk -F\; 'FNR==NR{arr=1;next};$3 in arr' core.txt gmrd.txt Any help appreciated (2 Replies)
Discussion started by: penfold
2 Replies
Login or Register to Ask a Question