Suffix formatting with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Suffix formatting with awk
# 1  
Old 11-07-2013
Suffix formatting with awk

i would like to format the 9 character with suffix as "0".

i tried below it doesn't work.

Code:
>a=12345
> echo $a | awk '{printf "%-09s\n",$1}'
>12345

required output is 123450000

can you guys help me out ?

Last edited by expert; 11-07-2013 at 02:03 AM.. Reason: required output update
# 2  
Old 11-07-2013
Like this?

Code:
echo $a | awk '{ if(length($0)<9) print $0 "0000";else print $0 }'

I assume you want output string length 9.

Last edited by greet_sed; 11-07-2013 at 02:29 AM.. Reason: updated code
# 3  
Old 11-07-2013
i am sorry . I forgot to mention that "a" will be of variable length 1-9 characters.
# 4  
Old 11-07-2013
Please see the updated code.
otherwise, post sample input & output data.
# 5  
Old 11-07-2013
input
Code:
1
12
123
1234
12345
123456
1234567
12345678
123456789

required output
Code:
100000000
120000000
123000000
123400000
123450000
123456000
123456700
123456780
123456789


Last edited by Scrutinizer; 11-07-2013 at 03:22 AM.. Reason: code tags
# 6  
Old 11-07-2013
Code:
echo $a | awk '{printf("%9.9s\n", $1 "00000000")}'

or with your latest example:
Code:
awk '{printf("%9.9s\n", $1 "00000000")}' input

This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 11-07-2013
thanks a lot guys.
it worked out Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

2. UNIX for Dummies Questions & Answers

awk print formatting

Hi all, Is it possible to tell awk that the first line of text is a header and then print dashes after it is printed before it prints the rest of the text? Note example below: Source file: Filesystem kbytes used avail capacity Mounted on server-p01:/vol/vol_vol01/db01... (3 Replies)
Discussion started by: newbie_01
3 Replies

3. Shell Programming and Scripting

Rsync script to rewrite suffix - BASH, awk, sed, perl?

trying to write up a script to put the suffix back. heres what I have but can't get it to do anything :( would like it to be name.date.suffix rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~" --bwlimit=1024 /mymounts/test1/ /mymounts/test2/ while IFS=. read -r -u 9 -d '' name... (1 Reply)
Discussion started by: jmituzas
1 Replies

4. Shell Programming and Scripting

AWK adding prefix/suffix to list of strings

75 103 131 133 138 183 197 221 232 234 248 256 286 342 368 389 463 499 524 538 (5 Replies)
Discussion started by: chrisjorg
5 Replies

5. UNIX for Dummies Questions & Answers

awk formatting

Hi all, I'm writing a simple awk code: awk 'BEGIN {FS="|"};{print "Type\tNumber\ttypes\tTotal";};{print $1, "\t", $2, "\t", $3, "\t", $4, "\t";}' db_query.txt it gives me the result: Type Number types Total XXX 498.0 5100.0 5274.661 Type Number types Total... (7 Replies)
Discussion started by: messi777
7 Replies

6. Shell Programming and Scripting

formatting awk

when i try this awk its giving out put as below. awk '!(/^$/||/--/||/selected/||/^ *$/){print $1}' tmp.txt output ===== 1 2010-08-03-12.31.26.126000 how excluede the 1st line ? i mean i want output only 2nd line i.e 2010-08-03-12.31.26.126000; (5 Replies)
Discussion started by: rocking77
5 Replies

7. Shell Programming and Scripting

AWK formatting help.

Dear all I require help with AWK regarding this situation Input is : fn1 12345 fn1 23456 fn3 231513 fn1 22325 fn3 123125 Desired output is fn1 12345 23456 22325 fn3 231513 123125 (5 Replies)
Discussion started by: Peasant
5 Replies

8. Shell Programming and Scripting

suffix a sequence in awk

hi I have a string pattern like ... ... 000446448742 00432265 040520100408 21974435 DEWSWATER GARRIER AAG IK4000 N 017500180000000000000000077000000000100 000446448742 00580937 040520100408 32083576 PEWSWATER BARRIER DAG GK4000 ... (6 Replies)
Discussion started by: zainravi
6 Replies

9. Shell Programming and Scripting

String formatting using AWK

Hi, I need to insert a line at a particular line number. I am using the below code: sed $REV_LINO_NO" i\\ # $CURRENT_DATE $NAME Changed pwd for cindy\'s id" file > file1 This code works, but the formatting is not as I expected. For example, I get lines as shown below... (2 Replies)
Discussion started by: sugan
2 Replies

10. Shell Programming and Scripting

Formatting using awk

Let's say I write a simple script that contains the following: date | awk '{print $1}' date | awk '{print $2}' Of course, when I run the script the output will look similar to: Tue Mar What if I want my ouput to be on one line as follows: Tue Mar What changes would I need to... (2 Replies)
Discussion started by: cdunavent
2 Replies
Login or Register to Ask a Question