I'm starting the first step in go and I'm needing it first get a text file to open it and filter by line where each line is separated by |
and I will make a if
to show certain line
Example:
Text file content:
|C100|1|0||55|05|1|000002397||||||||||||||||||||||
|C100|1|0||55|05|1|000002399||||||||||||||||||||||
|C100|1|0||55|05|1|000002425||||||||||||||||||||||
|C100|1|0||55|05|1|000002371||||||||||||||||||||||
|C400|2D|ECF|asdasda2330|002|
|C405|02012012|3|1036|116526|6001060,09|5693,36|
|C420|DT|151,78|||
|C420|01T1700|429,50|01||
|C420|F1|5112,08|||
|C460|2D|00|116397|02012012|25,00|0,16|0,75|||
|C470|0000008556|2,000|0|RL|25,00|060|5403|0|0,16|0,75|
|C460|2D|00|116398|02012012|27,67|0,19|0,83|||
|C470|0000015177|1,000|0|RL|5,60|060|5403|0|0,04|0,17|
|C470|0000022346|1,000|0|RL|5,60|060|5403|0|0,04|0,17|
|C470|0000025882|1,000|0|PC|6,09|060|5403|0|0,04|0,18|
|C470|0000025885|2,000|0|PC|10,38|060|5403|0|0,07|0,31|
|C460|2D|00|116399|02012012|19,90|0,13|0,60|||
|C470|0000000247|3,000|0|RLO|10,20|060|5403|0|0,07|0,31|
|C470|0000020634|1,000|0|PC|9,70|060|5403|0|0,06|0,29|
|C460|2D|00|116400|02012012|10,52|0,07|0,32|||
|C470|0000004762|1,000|0|CAT|1,12|060|5403|0|0,01|0,03|
|C470|0000008873|1,000|0|PC|1,94|060|5403|0|0,01|0,06|
|C470|0000016902|1,000|0|PC|3,68|060|5403|0|0,02|0,11|
|C470|0000023287|1,000|0|PC|1,26|060|5403|0|0,01|0,04|
|C470|0000023303|1,000|0|PC|1,26|060|5403|0|0,01|0,04|
|C470|0000023308|1,000|0|PC|1,26|060|5403|0|0,01|0,04|
|C460|2D|00|116401|02012012|5,00|0,04|0,16|||
|C470|0000009772|1,000|0|UN|1,25|000|5102|17,00|0,01|0,04|
|C470|0000009789|1,000|0|UN|1,25|000|5102|17,00|0,01|0,04|
|C470|0000009826|1,000|0|UN|1,25|000|5102|17,00|0,01|0,04|
|C470|0000009842|1,000|0|UN|1,25|000|5102|17,00|0,01|0,04|
I need to first open the file and store all its contents and then type an explode of each line by putting in an array
done this I'll make a if linha[1] == "C460"
and show the whole content of that line
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func main() {
conteudo,_ := ioutil.ReadFile("sped.txt")
linhas := strings.Split(string(conteudo),"|")
for _,v := range (linhas){
if v == "C100"{
fmt.Println(v) // preciso mostra a linha toda do registro C100
}
}
fmt.Println(linhas[1])
}