When running: aws s3 cp
command to upload a file from local to S3 it shows the following output:
upload: ./test.txt to s3://demo-bucket/test.txt
How do I extract only s3://demo-bucket/test.txt
string from the command output using grep
?
You can pipe the command to grep as follows:
grep -o 's3:\/\/.*$'
#s3://demo-bucket/test.txt
Note the usage of the -o
flag, which tells grep to only return the matched string.
You may also consider piping to awk :
awk '{print $4}'
#s3://demo-bucket/test.txt
which will print the fourth field of the string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.