0

I want the number of lines of my python files with relative path.

I get that like this::

$ find ./ -name "*.py" -exec wc -l {} \;| awk '{print $1, $2}'
29 ./setup.py
28 ./proj_one/setup.py
896 ./proj_one/proj_one/data_ns.py
169 ./proj_one/proj_one/lib.py
310 ./proj_one/proj_one/base.py
0 ./proj_one/proj_one/__init__.py
72 ./proj_one/tests/lib_test.py

How could I get (formated ints) like this::

 29 ./setup.py
 28 ./proj_one/setup.py
896 ./proj_one/proj_one/data_ns.py
169 ./proj_one/proj_one/lib.py
310 ./proj_one/proj_one/base.py
  0 ./proj_one/proj_one/__init__.py
 72 ./proj_one/tests/lib_test.py
user3313834
  • 7,327
  • 12
  • 56
  • 99

2 Answers2

1

You can use printf with a width format modifier to make a formatted column:

$ find ./ -name "*.py" -exec wc -l {} \;| awk '{printf "%10s %s\n", $1, $2}'

On most platforms, you can print with comma separators as a specifier (if you have BIG files) but the quoting can be challenging for command line use:

$ echo 10000000 | awk '{printf "%'\''d\n", $1}'
10,000,000
dawg
  • 98,345
  • 23
  • 131
  • 206
0

How about just pipping the output of find to column -t.

The column utility formats its input into multiple columns

-t Determine the number of columns the input contains and create a table. Read man page

za$ find . -name "*rb" -exec wc -l {} \; | column -t 
20   ./dirIO.rb
314  ./file_info.rb
53   ./file_santizer.rb
154  ./file_writer.rb
58   ./temp/maps.rb
248  ./usefu_ruby.rb 
z atef
  • 7,138
  • 3
  • 55
  • 50