Copy to a new file only those tapes that have a certain sequence of characters

Hello. I need help. In my code, the specified .txt file (with text) is copied in the specified path to the directory, but the code needs to be modified so that only those tapes that have a certain sequence of characters are copied to the new file. This can be done, I think, with Graph, but I don’t know how
I will be grateful for your help

package main

import (

func main() {
	read := make([]byte, 0, 64)
	var name, name2 string
	var path string
	fmt.Println("Set way to copy file:  ")
	fmt.Println("Set file name to copy:  ")
	wd, err := os.Getwd()
	if err != nil {
		fmt.Println("Error:", err)
	file, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, 0755)
	if err != nil {
	read, err = ioutil.ReadFile(name)
	defer file.Close()
	fmt.Println("Working Directory:  ", wd)
	fmt.Println("Application:  ", filepath.Join(wd, os.Args[0]))
	d := filepath.Join(wd, "Emperor")
	if err := os.Mkdir(d, 0755); err != nil {
		fmt.Println("Error:", err)
	fmt.Println("Created ", d)
	if err := os.Chdir(d); err != nil {
		fmt.Println("Error:", err)
	fmt.Println("Set name")
	file2, err := os.OpenFile(name2, os.O_RDWR|os.O_CREATE, 0755)
	if err != nil {
		fmt.Println("failed to copy the file")
	fmt.Println("New Working Directory: ", d)

by ‘tapes’ you mean ‘types’ ?

how about using regexp to search for pattern in files.
check examples here

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.