This is a creation in Article, where the information may have evolved or changed. //This program is designed to automatically animate real-time effects according to the contents of CVS, the seventh column is the last value
Usage: program name + file name
Packagemain
Import(
"Encoding/csv"
"Flag"
"FMT"
"io"
"Log"
"OS"
"strings"
)
FuncMain (){
//Parameters
flag. Parse ()
FMT. PRINTLN (flag. Narg ())
ifflag. Narg ()! = 1 {
Log. Printf ("Usage:command + filename")
return
}
//Take the 1th parameter as a filename
file, err: = OS. Open (flag. ARG (0))
iferr! = Nil {
FMT. Println ("Error:", err)
return
}
deferfile. Close ()
Reader: = csv. Newreader (file)
reader.comment = ' # '//can set the annotation in the read file
reader.comma = ', '//default is a comma, you can also set your own
//You can also set the following information
     // Fieldsperrecord int // number of expected fields per record
     // Lazyquotes bool // allow lazy quotes
     // Trailingcomma bool // allow trailing Span style= "font-size:18px" > comma
//trimleadingspace bool/ /Trim Leading Space
//line int
//column int
fout, err: = OS. OpenFile ("OUT.txt", OS. O_rdwr|os. O_append|os. O_create, 0666)
iferr! = Nil {
FMT. Println ("Error:", err)
return
}
deferfout. Close ()
Content: = ""
k: = 0//The first row is a field name and does not require
for{
record, err: = Reader. Read ()
iferr = = Io. EOF {
break
} else iferr! =Nil {
FMT. Println ("Error:", err)
return
}
ifk > 0 {//record is []strings, how to get the domain value directly
for _, V: = Range Record {
tmp: = strings. Split (V, "|")
//fmt. Print ("<" + Tmp[1] + ">" + Tmp[7] + "</" + Tmp[1] + ">")
content = content + "<" + tmp[1] + ">" + tmp[7 "+" </"+ tmp[1] +" > "
}
}
k = k + 1
}
FMT. Printf ("\ n")
Fout. WriteString (content + "\ n")
FMT. Printf ("\ n")
}