英文:
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 > 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 > 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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论