Created
May 22, 2022 19:53
-
-
Save tarunKoyalwar/2450744ac6095c466254def21c6444de to your computer and use it in GitHub Desktop.
Show Filetypes and frequency of S3 Bucket Object List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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