管道cat和perl时将输出重定向到文件

时间:2016-12-12 09:29:27

标签: bash pipe

我需要在文本文件中随机播放行并将结果存储到新的文本文件中。 这是我使用的命令。但是,这会将混洗的行打印到控制台而不是outfile。

getUniqueID: DB71DCB5-6BB0-497B-BE9E-A02BCC1235B7
getInstanceID: undefined
getDeviceId: x86_64
getManufacturer: Apple
getModel: Simulator
getBrand: Apple
getSystemName: iOS
getSystemVersion: 10.1
getBundleId: org.reactjs.native.example.project
getBuildNumber: 1
getVersion: 1.0
getReadableVersion: 1.0.1
getDeviceName:MacBook Pro
getUserAgent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B72
getDeviceLocale: en
getDeviceCountry: US
getTimezone: America/Panama
isEmulator: true
isTablet: false

2 个答案:

答案 0 :(得分:2)

未受保护的分号是罪魁祸首

它只是停止当前命令并启动另一个空命令(创建一个空文件)。

请注意"$@"的额外perl参数在这里没用,使用cat也是如此。总而言之,你可以写下:

perl -MList::Util=shuffle -e 'srand 123; print shuffle(<>);' infile > outfile

答案 1 :(得分:1)

删除最后一个;让它发挥作用。

cat infile | perl -MList::Util=shuffle -e 'srand 123; print shuffle(<>);' "$@" > outfile