-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraw_link.go
59 lines (48 loc) · 1.11 KB
/
raw_link.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
51
52
53
54
55
56
57
58
59
// Copyright (C) 2021 SeanTolstoyevski - mailto:seantolstoyevski@protonmail.com
//
// The source code of this project is licensed under the MIT license.
// You can find the license on the repo's main folder.
// Provided without warranty of any kind.
// Read the README for more information.
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
)
var (
inFile = flag.String("i", "backlink.txt", "Location of the file to be read")
outFile = flag.String("o", "fixed_backlinks.txt", "Name of the file to be written")
)
func main() {
flag.Parse()
bLinks, err := os.Open(*inFile)
if err != nil {
log.Fatal(err)
}
defer bLinks.Close()
fixedLinks, err := os.Create(*outFile)
if err != nil {
log.Fatal(err)
}
defer fixedLinks.Close()
scanner := bufio.NewScanner(bLinks)
for scanner.Scan() {
slashIndex := strings.Index(scanner.Text(), "/")
if slashIndex == -1 {
continue
}
fixText := scanner.Text()[:slashIndex] + "\r\n"
_, err := fixedLinks.Write([]byte(fixText))
if err != nil {
log.Fatal(err)
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
fmt.Println("Done")
}