-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws.go
More file actions
35 lines (27 loc) · 651 Bytes
/
Copy pathws.go
File metadata and controls
35 lines (27 loc) · 651 Bytes
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
package main
import (
"fmt"
"os"
"strings"
)
/* display the number of lines, words, and bytes in a file */
func ws() {
if len(os.Args) < 2 {
fmt.Println("Usage: go run cat.go <filename>")
return
}
fileName := os.Args[1]
fileContent, err := os.ReadFile(fileName)
if err != nil {
fmt.Println("error while reading the file content")
return
}
byteToStringFormat := string(fileContent)
individual_words := strings.Split(byteToStringFormat, " ")
fmt.Println("Lines:", strings.Count(byteToStringFormat, "\n")+1)
fmt.Println("Words:", len(individual_words))
fmt.Println("Bytes:", len(byteToStringFormat))
}
func main() {
ws()
}