-2

I want to share my codebase for others to get a glimpse without seeing all the details.

I just want them to see the directory structure and the first N lines of every file.

How can I do this using bash or some other standard scripting language like python?

NOTE: If some other tool can do this, it would also work

phd
  • 82,685
  • 13
  • 120
  • 165
danielrvt
  • 10,177
  • 20
  • 80
  • 121
  • 1
    This seems to have nothing to do with Git or GitHub (even if you intend to use the result with them later, they're not relevant to how you would do this in code). – torek Oct 31 '19 at 01:12
  • 2
    pluse uno for more interesting than average Q ;-) Good luck. – shellter Oct 31 '19 at 01:16

2 Answers2

-1

Something like this will do the trick:

import os

for r, d, files in os.walk('.') :
    for f in files :
        name = os.path.join( r, f )

        with open( name ) as fin :
            text = fin.readlines()[:20]

        with open( name, 'w' ) as fout :
            fout.write( ''.join( text ) )
lenik
  • 23,228
  • 4
  • 34
  • 43
-1

One way using :

find . -type f -exec sed -i.bak '21,$d' {} \;
Steve
  • 51,466
  • 13
  • 89
  • 103