Slice A Given Txtfile And Write Only Part Of It In A Newfile In Python
This is my original .txt data:
HKEY_CURRENT_USER\SOFTWARE\7-Zip HKEY_CURRENT_USER\SOFTWARE\AppDataLow HKEY_CURRENT_USER\SOFTWARE\Chromium HKEY_CURRENT_USER\SOFTWARE\Clients HKEY_CURRENT_USER\SOFTWARE\CodeBlocks HKEY_CURRENT_USER\SOFTWARE\Discord HKEY_CURRENT_USER\SOFTWARE\Dropbox HKEY_CURRENT_USER\SOFTWARE\DropboxUpdate HKEY_CURRENT_USER\SOFTWARE\ej-technologies HKEY_CURRENT_USER\SOFTWARE\Evernote HKEY_CURRENT_USER\SOFTWARE\GNU
And I need to have a new file where the new lines contain only part of those strings, like:
7-Zip AppDataLow Chromium Clients ...
how to do it in python?
## read file content as string with open("file.txt", "r") as file: string = file.read() ## convert each line to list lines = string.split("\n") ## write only last part after "\" in each line with open("new.txt", "w") as file: for line in lines: file.write(line.split("\\")[-1] + "\n")
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module