如何在不对段落进行任何操作的情况下将段落回显到文件中。 我的意思是换行符,空格,特殊字符等,所有缩进都应该相同。
我的.bat文件(包含.ppk文件的内容)
echo (PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20130127
Public-Lines: 6
AAAAB3NzaC1yc2EAAAABJQAAAQBVYEVYbGluh1Ne6psUMsK4TRiqwN8GG+ImbsfC
qIYje3S7n3owtEUSDMEc5VvTZTEXk/CKHK6tXhGSNrExXKDhKE2HejY7TFtbc3vU
KM4OogxYeZs/0yBX/kVEu5+kIeZ0ZEsq/ve9/hnEVLZ3DFotUoDzzwdd4jAHUZv2
08xk5tTxodh+iO26RVPSaklZrFjbZkqCwPOnVZhK6JqE/7kZyIM+p5W8CH8XPG3r
fgU/R4BpwMNz+pYo2iiV3eZApI25lY+IcjclA5Amx1JdCM1zIvA6C8ABUbTMXsyG
RHkzdEYjw5+pBF8qLU8s8+M9sw0l5z58dP9t+vuYWz+JrsmL
Private-Lines: 14
AAABAECb4XNY9dcaTO3h+NED0aA6V9sqLDv5bN7QX9GUSdWpiMVWF0dzqeQlU96E
DiNvLBHXvPLlRer7FDdL+7am9kmGSIIy+JuTusG/LUaba4Cx+4E5bpEqJlBtZNoR
ceP9+oGYAYhSPvCkneCuz0VVdKytI1C4WJoS8+nc5LrJyxvsFGgVEIo5nadkABRV
eOLwotq2Mj/lLXHMbE5lB+9m9VNsWrBErNVCwNQdhQOyG1E39YcwBV+hB+Pyu41z
6EHxIRXQvbYNE2HjLvowrnX/9fFfx1kf51+WE+VbFQxrrZqE1p3y2S2kJkAopRio
KZBlNwrR6mwSLtRn4a6ZecKwVE0AAACBAJVV6O5leR0gl27DVqnXu6mhf6Xb8Ije
2JfvLCa73bgpFSYQ2EpxKTiSpZpM3kPpnC7Y0SvigstGHwze/OuCXYnzT/KDkBrs
NDPiuTSmzW3JxtGv1axpfRRt/PaRIHq6pCtyGxIc5A0RrTuSrPzZkHxFggkAYSMK
9YOi1sZhcVtlAAAAgQCSW1Pvq4zSjsUuGMc/w8T8mOOZG4Yllq7e9CSpTMeqeVHl
Vytm5+ujIyas/k/UGA8WQt3ZnD5uLF7tBRoaHf88oE00nXVnLlDeME3Jdbts84tE
1HB9RzwGE+BVknEiNcUjqhVcRqv6+pOClR+K5VOstqs/tmmMOA57c1481K/aLwAA
AIAQn9Fhg4Ih71uvber4RELcZCQrvRFsuASYHrgYBkzw17PTPQ9APv0B1nIPZ/u6
+jhou7qzR78yrYw0Po4ZJmmDt0CP/cZPWL4jQ6sM6on98D6TdKk7rE1c0WPn1Bta
ZtaxQqOku7eAfw745L9EjokekZjohjTFI9rSFdsCfa6dXw==
Private-MAC: 2e75877ab827b492b2a0a16c5019cd45f96e4990) > myfile.txt
将我保存为.bat并执行
后,上述行无效我想将段落放在具有唯一名称的文件中,以便它不会覆盖任何现有文件。 我是否需要在每一行回应并继续追加。
答案 0 :(得分:2)
在最终的EXIT / B之后放置一个唯一的文本标记,然后是你的段落。使用带有FINDSTR的FOR / F来定位唯一标记,然后使用FOR / F循环处理标记之后的所有行。
有许多变化,每种都有不同的限制。
这是最简单的形式,但也有最多的限制。这些限制在文中描述。
@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
for /f "usebackq skip=%skip% delims=" %%A in ("%~f0") do echo(%%A
)
type test.txt
exit /b
:::BeginText
This text will be exactly preserved with the following limitations:
1) Each line will be terminated by CR LF even if original has only LF.
2) Lines are limited in length to approximately 8191 bytes.
3) Empty lines will be stripped.
; 4) Lines beginning with ; will be stripped.
5) The text will be truncated at the first occurance of hex code 0x1A (Ctrl-Z).
Special characters like ^ & < > | etc. do not cause a problem
一些奇怪的FOR / F选项语法消除了以;
@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
for /f ^usebackq^ skip^=%skip%^ delims^=^ eol^= %%A in ("%~f0") do echo(%%A
)
type test.txt
exit /b
:::BeginText
This text will be exactly preserved with the following limitations:
1) Each line will be terminated by CR LF even if original has only LF.
2) Lines are limited in length to approximately 8191 bytes.
3) Empty lines will be stripped.
4) The text will be truncated at the first occurance of hex code 0x1A (Ctrl-Z).
Special characters like ^ & < > | etc. do not cause a problem
;Lines beginning with ; are preserved
读取FINDSTR / N输出而不是直接读取文件保留空行。但是引入了领先:
的新限制。
@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
for /f "skip=%skip% tokens=1* delims=:" %%A in (
'findstr /n "^" "%~f0"'
) do echo(%%B
)
type test.txt
exit /b
:::BeginText
This text will be exactly preserved with the following limitations:
1) Each line will be terminated by CR LF even if original has only LF.
2) Lines are limited in length to approximately 8191 bytes.
::: 3) Leading : will be stripped from each line.
Special characters like ^ & < > | etc. do not cause a problem
Empty lines are preserved!
;Lines beginning with ; are preserved.
这个最终版本和它一样好。必须打开和关闭延迟扩展,以保留可能出现在文本中的!
。
@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
for /f "skip=%skip% tokens=*" %%A in (
'findstr /n "^" "%~f0"'
) do (
set "line=%%A"
setlocal enableDelayedExpansion
echo(!line:*:=!
endlocal
)
)
type test.txt
exit /b
:::BeginText
This text will be exactly preserved with the following limitations:
1) Each line will be terminated by CR LF even if original has only LF.
2) Lines are limited in length to approximately 8191 bytes.
Special characters like ^ & < > | etc. do not cause a problem.
Empty lines are preserved!
;Lines beginning with ; are preserved.
:::Leading : are preserved.