- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人可以在这里解释我的误解吗? cat 一些文件 | cat
正在输出 10000 行而不是 100 行。我习惯了管道的 Unix 行为。这是重现问题的脚本(需要在 PowerShell 提示符下逐行输入):
seq 1 100 > somefile
cat somefile # works as expected, outputs 100 lines
cat somefile | Measure-Object # 100 lines, expected.
cat somefile | cat # OUTPUTS 10000 lines!!!
# wait did I really just see that
cat somefile | cat | Measure-Object
# 10000 lines??!!!
cat somefile | cat | cat | Measure-Object
# 57300 lines??? That's not even a pattern!
很明显,我不知道这里发生了什么。我期待 bash 行为。我知道做 cat somefile | 没有用cat
,但这仍然令人惊讶。
Bash 行为是 cat somefile |猫 |猫 | cat
始终提供与 cat somefile
完全相同的内容。
最佳答案
Get-Content
的别名 cat
是出于我认为的方便原因而引入的(让 Unix 用户对 PowerShell 感觉更舒服)。不过,这并不会使 Get-Content
的行为与 Unix 命令 cat
完全相同。该 cmdlet 特别不会回显来自管道的字符串输入:
PS C:\Temp> 'foo' | catcat : The input object cannot be bound to any parameters for the command eitherbecause the command does not take pipeline input or the input and its propertiesdo not match any of the parameters that take pipeline input.At line:1 char:9+ 'foo' | cat+ ~~~
这就是 Write-Output
(或其别名 echo
)的用途:
PS C:\Temp> 'foo' | Write-Outputfoo
接受管道输入的Get-Content
的默认参数分别是-Path
和-LiteralPath
,它们都需要一个有效的路径.
在仔细检查 Get-Content
的输出后,您会注意到这些对象不仅具有字符串对象的通常属性,而且还具有一些包含数据来源文件信息的属性已读取,特别是 PSPath
:
PS C:\Temp> 4..6 > out.txtPS C:\Temp> cat .\out.txt456PS C:\Temp> cat .\out.txt | Get-Member TypeName: System.StringName MemberType Definition---- ---------- ----------...PSChildName NoteProperty string PSChildName=out.txtPSDrive NoteProperty PSDriveInfo PSDrive=CPSParentPath NoteProperty string PSParentPath=C:\TempPSPath NoteProperty string PSPath=C:\Temp\out.txtPSProvider NoteProperty ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystemReadCount NoteProperty long ReadCount=1Chars ParameterizedProperty char Chars(int index) {get;}Length Property int Length {get;}
PSPath
属性用作第二个 Get-Content
的输入,导致输入文件中的每一行触发另一个 Get-Content
相同的文件。但是,第一个 Get-Content
的输出对象也有一个属性 ReadCount
(表示已经从文件中读取的行数),这也会发生成为 Get-Content
的参数。因此,第二个 Get-Content
读取输入文件的方式与第一个不同完全。 ReadCount=2
一次读取文件中的 2 行,ReadCount=3
一次读取 3 行,依此类推。
PS C:\Temp> cat .\out.txt | cat4 # ← input line 1 ("4"), ReadCount = 1, 1st read (returns "4")5 # ← input line 1 ("4"), ReadCount = 1, 2nd read (returns "5")6 # ← input line 1 ("4"), ReadCount = 1, 3rd read (returns "6")4 # ← input line 2 ("5"), ReadCount = 2, 1st read (returns "4", "5")56 # ← input line 2 ("5"), ReadCount = 2, 2nd read (returns "6")4 # ← input line 3 ("6"), ReadCount = 3, 1st read (returns "4", "5", "6")56
因为额外的管道步骤 (cat .\out.txt | cat | cat ...
) 不会产生 nm 输出行 ( n
是文件中的行数,m
是流水线步骤数)。
关于powershell - powershell 中的 `cat somefile | cat` 给出 10000 行而不是 100 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54544355/
如何从表中选择结果,其中 cat = '$cat',如果不相等,则从 cat 中选择所有结果,无论 $cat 是什么。这是我的查询 $sql = mysql_query("SELECT * FROM
如标题中的示例,我想要结果: 目录:home/tom/cat 第一次剪辑:tom/cat 第二次切割:/cat 最后一刀:/ 如何在 python 中实现? 最佳答案 这是您要找的吗: In [101
使用循环,我可以创建 My cat is: Cat1 ... My cat is: Cat1 但是,当我尝试使用 Cat ("cat"+i) = new Cat("Cat" + i); 我犯错了.
我目前正在用 C 和 unix 开发一个 cat 命令。这次我的任务是设计 cat -b 和 cat -s 命令。但是我已经创建了其他命令,例如 -t、-v、-n、-e。我卡在了命令 -b 中,因为每
我理解这一点的方式是命令 cat file 将显示文件的内容并 cat < file 将把文件的内容作为输入。我正在尝试这个并创建了两个文件。一个名为 file1.txt,另一个名为 file2.tx
我理解这一点的方式是命令 cat file 将显示文件的内容并 cat < file 将把文件的内容作为输入。我正在尝试这个并创建了两个文件。一个名为 file1.txt,另一个名为 file2.tx
我有一个程序可以同时读取两个输入文件。我想从标准输入中读取这个程序。我以为我会使用这样的东西: $program1 <(cat) <($program2) 但我刚刚发现 cat <(cat) 产生 .
管道的正式定义指出左侧文件的 STDOUT 将立即通过管道传输到右侧文件的 STDIN。我有两个文件,hello.txt 和 human.txt 。 cat hello.txt 返回 Hello 并且
我想编写一个 shell 脚本,它接受来自标准输入的数据,将它写入一个文件,然后用它做一些事情。 出于这个问题的目的,让我们假设我的脚本应该接受标准输入,将其写入 in.txt ,然后 grep 一个
有没有办法让cat , less等打印制表符而不是制表符被转换为空格?当我将代码从终端复制到编辑器时,我对此很恼火。 最佳答案 我在这里看到两个问题。 首先,目标编辑器可以将 TAB 转换为空格数。一
我刚刚发现执行 find . 比执行 find 慢。 |猫。这是在我的主目录中执行 time find . 3 次的结果: First: real 0m4.385s user 0m0.54
我相信该程序适用于除一个以外的大多数情况。我在 indexOF() 中添加了空格,所以像 cathrine 和 dogsuit lammas 这样的词都会被认为是非亵渎的。我看到的唯一问题是用户是否以
解决方案: 不支持 data-* 属性。您可以定义自己的属性并使用 getAttribute 调用它们。就我而言, this.dataset.cat 变为 this.getAttribute("cat
这是让我“我该怎么办?”的问题之一 这是我遇到的编译器错误: 在“SKFootmanSprite”类型上使用实例成员“getAttackUPSequence_Frames”您是否打算改用“SKFoot
我想将 2 个不同的 cat 语句合并为一个 cat 语句 cat /dir1/file1.cfg | grep -q "linux" cat /dir1/file2.cfg | grep -q "l
我已经在 C 中使用系统调用(打开、读取和写入)来模拟 Linux 系统中的“猫”功能,并且它比真实的慢... 我正在使用与真正的“cat”相同的缓冲区大小,并使用“strace”我认为它进行相同数量
我在不同的示例、教程、博客等中看到过这两种格式,但就我的生活而言,我找不到对差异的解释。有什么区别 ICriteria crit = session.CreateCriteria(typeof(Cat
我在不同的示例、教程、博客等中看到过这两种格式,但就我的生活而言,我找不到对差异的解释。有什么区别 ICriteria crit = session.CreateCriteria(typeof(Cat
我有一个包含列的表:(project_id, name) 这是一个人员列表,每个人都有其所属的项目。如果一个人在两个项目中,则重复。 我想提取一个包含以下列的表:(project_id, people
我想提取 git 存储库中保存的文件的最新版本的副本,并将其传递到脚本中进行某些处理。对于 svn 或 hg,我只使用“cat”命令: Print the specified files as the
我是一名优秀的程序员,十分优秀!