1

I am trying to read the head of a gz file using awscli without downloading. I am using the command

aws s3api get-object --bucket mybucket_name --key path/to/the/file.log.gz --range bytes=0-10000 /dev/stdout | zless 

which I found in the link https://stackoverflow.com/questions/25983769/head-command-for-aws-s3-to-view-file-contents?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

I am able to read head of simple txt files, but how to do it for .gz files. Or any other way using some other tool if it can be accomplished?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Aklank Jain
  • 1,002
  • 1
  • 13
  • 21

1 Answers1

1

One easy way to do is :-

aws s3api get-object --bucket bucket_name --key path/to/file.txt  --range bytes=0-10000 /path/to/local/t3.txt | cat t3 | head -1

For the gz file , you can do

aws s3api get-object --bucket bucket_name --key path/to/file.gz  --range bytes=0-10000 /path/to/local/t3 | zless t3 | head -1
Aklank Jain
  • 1,002
  • 1
  • 13
  • 21