Printf formatting

From thelinuxwiki
Revision as of 05:14, 10 January 2014 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

if you want information overload...go here http://wiki.bash-hackers.org/commands/builtin/printf


simple column width formatting + justification

$ printf "%10s%10s\n" "foo" "bar"                                                                                                            
      foo       bar
$ printf "%-10s%10s\n" "foo" "bar"            kkkj                                                                                               
foo              bar
$ printf "%10s%-10s\n" "foo" "bar"                                                                                                           
      foobar       
$ printf "%-10s%-10s\n" "foo" "bar"                                                                                                          
foo       bar       


scientific notation to decimal conversion

# echo "8.46145e+09" | awk  '{ printf ("%.0f\n",$1) }'    
8461450000

where the %.0f does the work... 0 is for 0 decimal places, f = floating point