简体   繁体   English

Grep在S3文件夹中对文件进行排序

[英]Grep sorted files in S3 folder

I'd like to sort files in S3 folders and then check if files contain a certain string. 我想对S3文件夹中的文件进行排序,然后检查文件是否包含某个字符串。

When I usually want to grep a file I do the following: 当我通常要grep文件时,请执行以下操作:

aws s3 cp s3://s3bucket/location/file.csv.gz - | zcat | grep 'string_to_find' 

I see I can sort files like this: 我看到我可以对文件进行排序:

aws s3api list-objects-v2 \
--bucket s3bucket \
--prefix location \
--query 'reverse(sort_by(Contents,&LastModified))'

Tried something like this so far but got broken pipe: 到目前为止,已经尝试过类似的操作,但是管道破裂:

aws s3api list-objects-v2 \
--bucket s3bucket \
--prefix location \
--query 'reverse(sort_by(Contents,&LastModified))' | cp - | zcat | grep 'string_to_find'

You can specify which fields to output and force them into text-only: 您可以指定要输出的字段并将其强制为纯文本:

aws s3api list-objects-v2 \
--bucket s3bucket \
--prefix location \
--query 'reverse(sort_by(Contents,&LastModified))[].[Key]' \
--output text

Basically, the sort_by and reverse output the Contents array, and this extracts the Key element. 基本上, sort_byreverse输出Contents数组,这将提取Key元素。 I put [Key] in square brackets to force each result onto its own line. 我将[Key]放在方括号中,以将每个结果强制放在自己的行上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM