Created
August 12, 2018 07:26
-
-
Save montanaflynn/4b573f09ce6e4e1989e9d22149cfb43a to your computer and use it in GitHub Desktop.
Simple wildcard concatenation program
This file contains hidden or 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 ( | |
"bytes" | |
"io/ioutil" | |
"log" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
if len(os.Args) == 1 { | |
log.Fatalln("Missing required argument.") | |
} | |
pattern := os.Args[1] | |
files, err := filepath.Glob(pattern) | |
if err != nil { | |
log.Fatalf("Failed to get list of files from pattern: %s\n", pattern) | |
} | |
var buffer bytes.Buffer | |
for _, file := range files { | |
data, readErr := ioutil.ReadFile(file) | |
if readErr != nil { | |
log.Printf("Could not read file: %s due to error %s)\n", file, readErr) | |
} else { | |
buffer.Write(data) | |
} | |
} | |
_, err = buffer.WriteTo(os.Stdout) | |
if err != nil { | |
log.Fatalf("Could not write buffer to standard output: %s\n", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment