-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (48 loc) · 934 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
myFile := os.Args[2]
argsWithoutProg := os.Args[1:]
if argsWithoutProg[0] == "-c" {
MyFile, err := os.Stat(myFile)
if err != nil {
fmt.Println(err)
}
fmt.Println(MyFile.Size(), myFile)
}
if argsWithoutProg[0] == "-l" {
readFile, err := os.Open(myFile)
if err != nil {
fmt.Println(err)
}
scanner := bufio.NewScanner(readFile)
var count int
for scanner.Scan() {
count++
}
fmt.Println(count)
defer readFile.Close()
}
if argsWithoutProg[0] == "-w" {
readFile, err := os.ReadFile(myFile)
if err != nil {
fmt.Println(err)
}
result := strings.Fields(string(readFile))
fmt.Println(len(result), myFile)
}
if argsWithoutProg[0] == "-m" {
readFile, err := os.ReadFile(myFile)
if err != nil {
fmt.Println(err)
}
data := string(readFile)
result := len(([]rune)(data))
fmt.Println(result, myFile)
}
}