I want to remove the content form the list of files.
EDIT :
I have list of files.
file1 file2 file3
Those file containing bunch of lines ...
I want to remove all the lines from each files.
Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.
Use the truncate() Function to Clear the Contents of a File in Python. The truncate() method in the Python file handling allows us to set the size of the current file to a specific number of bytes. We can pass the desired size to the function as arguments. To truncate a file, we need to open it in append or read mode.
Looks like you need to truncate file. Do something like:
File.open('/tmp/file', 'w') {|file| file.truncate(0) }
To truncate a file:
File.truncate('/path/to/file', 0)
To truncate list of files:
[file1, file2, file3].each { |file| File.truncate(file, 0) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With