回声段落到一个文件中的内容不做任何修改的段落? [英] Echo the contents of a paragraph into a file without any modifications to the paragraph?

查看:110
本文介绍了回声段落到一个文件中的内容不做任何修改的段落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何呼应的段落到一个文件中没有做任何操作的段落。
我的意思是换行,空格,特殊字符等,所有的压痕应该是一样的。

How do i echo a paragraph into a file without doing any kind of manipulation to the paragraph. i mean newline,space,special characters etc and all the indentation should be same.

我的.bat文件(包含.ppk文件的内容)

My .bat file(containing the contents of .ppk file)

    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和执行

The above line does not work after i save it as .bat and execute

我想把段落中的一个文件,一个唯一的名称,以便它不会覆盖已经存在的文件。
我需要在每一条线路回声,并保持附加。

i want to put the paragraph in a file with a unique name so that it does not overwrite any existing file. Do i need to echo at each and every line and keep appending.

推荐答案

放到最后EXIT / B后的一个独特的文本标记,然后是你的段落。使用FOR / F与FINDSTR定位独特的标记,然后用FOR / F循环来处理标记之后的所有行。

Put a unique text marker after the final EXIT /B, followed by your paragraph. Use FOR /F with FINDSTR to locate the unique marker, and then use a FOR /F loop to process all the lines after the marker.

有许多的变化,每一个具有不同的限制。

There are many variations, each with different limitations.

下面是最简单的形式,但它也有最局限性。限制在文中所描述

Here is the simplest form, but it also has the most limitations. The limitations are described in the text.

@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输出,而不是读文件直接preserves空行。但与领先的新限制介绍

@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.


这个最终版本,因为它得到一样好。延迟扩展必须打开和关闭,以preserve进行切换可能出现在文本中。

@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.

这篇关于回声段落到一个文件中的内容不做任何修改的段落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆