How to pipe input to gsutil cp from stdin?
Asked Answered
N

2

10

I am looking for a way to pipe the data into gsutil cp:

echo '<html>foobar</html>' | gsutil cp --stdin gs://my-bucket/foo

the -I option is for reading filepaths, not the data..gsutil help cp says:

https://gist.github.com/ORESoftware/566d9c3d00e3858c1161ae9b741fc07e

So yeah I am looking for a way to send files to GS via stdin.

Nitrile answered 24/1, 2020 at 21:29 Comment(0)
N
17

Looks like it works using - like so:

echo '<html>foobar</html>' | gsutil cp - gs://my-bucket/foo

in my opinion, a --stdin flag would be more explicit and preferred.

Nitrile answered 24/1, 2020 at 21:44 Comment(1)
Almost everything in Unix that reads from a file, or writes to a file, accept - to mean stdin and stdout respectively. This is consistent with half a century of every single command line tool. So that is to say I disagree with you. :-)Bacchic
A
-1

From the docs:

You can use the -I option with stdin to specify a list of URLs to copy, one per line. This allows you to use gsutil in a pipeline to upload or download objects as generated by a program:

cat filelist | gsutil -m cp -I gs://my-bucket 

or:

cat filelist | gsutil -m cp -I ./download_dir 

where the output of cat filelist is a list of files, cloud URLs, and wildcards of files and cloud URLs.

Affiance answered 24/8, 2022 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.