tabs changed to spaces when copy & pasting
I am editing a python script in a putty terminal. A copy and paste causes tabs to be replaced with spaces, even in the same terminal, which causes problems. Is this putty behavior? Nano behavior? Something in windows? I could mark and copy since I am using nano, but eventually the revised script changes need to be pasted back into the Linux system I created the script on. That system does not have an AMD board and I am testing the script on a system that does using putty to access each system
2 Answers
I suspect that's putty behavior. You can use the sed command to replace leading spaces with tab characters:
sed "s/ /\t/g" filenameThe example above replaces 4 leading spaces with 1 tab. Change the number of spaces to suit your needs. If the output looks right, you can save the changes to the original file instead of printing it to standard out:
sed -i "s/ /\t/g" filename My fix has been, if I am editing something on Windows which I will run as a script in Linux later, is to use Notepad++. It has a nifty feature; under Edit, you can choose EOL Conversion then change a file from Windows to Linux -or- MacOS EOL formatting!