Remove trailing spaces from a file using Windows batch?

前端 未结 7 1303
借酒劲吻你
借酒劲吻你 2020-12-02 02:33

How could I trim all trailing spaces from a text file using the Windows command prompt?

7条回答
  •  萌比男神i
    2020-12-02 03:09

    I use this Python 2 script to print lines with trailing whitespace and remove them manually:

    #!/usr/bin/env python2
    import sys
    
    if not sys.argv[1:]:
      sys.exit('usage: whitespace.py ')
    
    for no, line in enumerate(open(sys.argv[1], 'rb').read().splitlines()):
      if line.endswith(' '):
        print no+1, line
    

    I know that Python is not preinstalled for Windows, but at least it works cross-platform.

提交回复
热议问题