Editing python files

3

I have the intention of inserting into the files .py the following section:

-*- encoding: utf-8 -*-

It needs to be specific online, and in large amount of files.

Is there any unix / linux tool that can perform this task?

    
asked by anonymous 10.06.2015 / 21:16

1 answer

2

To insert this line, use the command sed :

sed -i '2i-*- encoding: utf-8 -*-' arquivo.py

  • -i saves edits to the file itself
  • 2i i nsere the string in the second line

To do this in all python files in the same folder, replace arquivo.py with *.py . You can use other wildcard characters .

    
12.06.2015 / 22:03