Document directory
- 1: Use the SED command
- 2: run the vim command.
- 3: shell script
I found many methods on the Internet. Here I just summarized them and used my test results.
1: Use the SED command
DFS is the file name with empty rows
A: sed-I '/^ \ s * $/d' DFS
Note: The-I option is to directly modify the file without printing out the modified content of the file. Without-I, the modified content is printed, but the content of the file is not changed.
B: sed '/^ $/d' DFS
Note: ^ indicates that the beginning $ indicates that the end d is deleted. This sentence indicates that the beginning and end of the line do not contain any characters. Delete
2: run the vim command.
I saw some netizens say that g/^ \ s * $/g can be implemented. I tried and found that it could not work. The following error cannot be recursive:
: G/^ \ s * $/g
E147: Global cannot be recursively executed
Press ENTER or another command to continue
However, you can use g/^ \ s * $/to print the location of the empty row.
: G/^ \ s * $/
4
6
8
11
13
Press ENTER or another command to continue
For more comments on VIM commands, I know they can be implemented.
I got a method by referring to comments from netizens. I know SED is used to delete it with D. I didn't expect it to be done with vim. Sorry... thanks to the two comments!
Delete empty lines under Vim. Command
: G/^ $/D or: G/^ \ s * $/d
3: shell script
If [$ #-ge 1]; then
For each in $ @
Do
If [-F $ each]; then
Name = "tmp _ $ each"
Sed-e '/^ $/d' $ each> $ name
Rm $ each
MV $ name $ each
Else
Echo "rmnone: no such file $ each"
Fi
Done
Else
Echo "rmnone: no input file"
Exit
Fi
This is the script of a netizen. I didn't test it. For convenience, we can give the shell program executable right and put it under/bin, so that we can use this tool like using shell commands.