如何将从文件复制的文本粘贴到另一个目录的新文件中

huangapple go评论65阅读模式
英文:

Hot to paste a text copied from a file using cmd " Get-Content -Raw file_name | clip " to a new file in another directory

问题

I copy a text from .cpp file using the command-line using this command Get-Content -Raw file_name | clip in Windows 10
and I'm trying to paste that text into another file in another directory.

I've tried using the cat command to redirect the output to a new file like cat -Raw file_name > path_to_new_file. It works, but I want to paste the same text to more than one path.

The point is, is there any keyword or alias that stores the text copied earlier to paste it where I want or is there any keyword or alias that returns the last copy in the clipboard.

Can someone please help me with this issue? How can I paste the copied text to a file in another directory using the command prompt?

英文:

I copy a text from .cpp file using the command-line using this command Get-Content -Raw file_name | clip in Windows 10
and I'm trying to paste that text into another file in another directory

I've tried using the cat command to redirect the output to a new file like <br> cat -Raw file_name &gt; path_to_new_file <br> it works , but I want to paste the same text to more than one path

the point , is there any keyword or alias that store the text copied earlier , to paste it where I want
or is there any keyword or alias return the last copy in the clipboard

Can someone please help me with this issue? How can I paste the copied text to a file in another directory using the command prompt ?

I've tried using the cat command to redirect the output to a new file like <br> cat -Raw file_name &gt; path_to_new_file <br> it works , but I want to paste the same text to more than one path

答案1

得分: 1

要调用剪贴板内容,请使用 Get-Clipboard

# 将内容放入剪贴板
Get-Content -Raw file_name | Set-Clipboard

# 您可以随意多次检索它
1..10 | ForEach-Object {
    Get-Clipboard
}

话虽如此,您不需要使用剪贴板 - 只需将文件内容存储在变量中并引用它即可:

# 将内容放入变量
$rawContent = Get-Content -Raw file_name

Get-ChildItem .\path\to\target\files -Filter *.ext | ForEach-Object {
    # 追加到目标文件
    $rawContent | Add-Content -LiteralPath $_.PSPath
}
英文:

To recall the clipboard contents, use Get-Clipboard:

# put content in clipboard
Get-Content -Raw file_name |Set-Clipboard

# retrieve it as many times as you like
1..10 |ForEach-Object {
    Get-Clipboard
}

That being said, you don't need to use the clipboard - simply store the file contents in a variable and reference that:

# put content in variable
$rawContent = Get-Content -Raw file_name

Get-ChildItem .\path\to\target\files -Filter *.ext |ForEach-Object {
    # append to target file(s)
    $rawContent |Add-Content -LiteralPath $_.PSPath
}

huangapple
  • 本文由 发表于 2023年6月6日 00:02:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定