doude1917 2016-07-31 14:11
浏览 156


I want to do this:

  1. Read a line from a text file.
  2. Process the line.
  3. Delete the line.

My first thought was to read the entire file into memory with ioutil.Readfile(),
but I'm not sure how to update the text file after the line has been processed,
and what happens if extra lines is added to the text file after it has been read into memory?

I normally write shell scripts and would do something like this:

while read -r line; do
    echo "${line}"
    sed -i 1d "${myList}"
done < "${myList}"

What is the best way to do this in Golang?

  • 写回答

2条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 Win7电脑开机出现硬件设置已更改
      • ¥15 vba代出现莫须有错误,都是一个个复制下来的为啥出错呢?
      • ¥15 /etc/vsftpd/vsftp.conf配置文件加了一行utf8_filesystem=YES之后,启动vsftpd报错
      • ¥15 W5100可以收广播,但是无法发出广播
      • ¥100 PCD点云排序和分割
      • ¥15 GG-CNN抓取数据集
      • ¥15 C++类和对象,多态性,继承,虚函数虚基类
      • ¥15 使用VS2019和Dev c++按%p输出地址,结果相差很大
      • ¥30 有偿解惑TINA老报错,求解惑
      • ¥15 arduino esp8266 编译问题