Skip to content

Instantly share code, notes, and snippets.

@tarunKoyalwar
Created May 22, 2022 19:53
Show Gist options
  • Save tarunKoyalwar/2450744ac6095c466254def21c6444de to your computer and use it in GitHub Desktop.
Save tarunKoyalwar/2450744ac6095c466254def21c6444de to your computer and use it in GitHub Desktop.
Show Filetypes and frequency of S3 Bucket Object List
package main
import (
"fmt"
"io/ioutil"
"strings"
)
/*
Save Output of aws command to file with `filelist.txt` and run
go run ./main.go
*/
func main() {
filetypes := map[string]int{}
data, err := ioutil.ReadFile("fileslist.txt")
if err != nil {
panic(err)
}
stringdata := string(data)
lines := strings.Split(stringdata, "\n")
for _, v := range lines {
parts := strings.Split(v, ".")
suffix := parts[len(parts)-1]
if filetypes[suffix] == 0 {
filetypes[suffix] = 1
} else {
filetypes[suffix] = filetypes[suffix] + 1
}
}
for k, v := range filetypes {
fmt.Printf("%v : %v\n", k, v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment