如何用sed命令往空文件中写入数据
发布网友
发布时间:2022-04-21 11:58
我来回答
共2个回答
热心网友
时间:2023-09-17 19:12
sed是基于行来处理的文件流编辑器,如果文件为空的话,它是处理不了的!找了段英文的解释如下:
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a
pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over
the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distin-
guishes it from other types of editors.
大致情形就是:
linux@host~# cat file.txt // 里面没有内容
linux@host~# touch file.txt // 新建一个空文件
linux@host~# cat file.txt // 里面没有内容
linux@host~# sed -i "\$a $var" file.txt // 往文件里面添加变量中的数据
linux@host~# cat file.txt // 但文件里面还是没有内容
linux@host~#
热心网友
时间:2023-09-17 19:13
sed是基于行来处理的文件流编辑器,如果文件为空的话,它是处理不了的!找了段英文的解释如下:
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a
pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over
the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distin-
guishes it from other types of editors.
大致情形就是:
linux@host~# cat file.txt // 里面没有内容
linux@host~# touch file.txt // 新建一个空文件
linux@host~# cat file.txt // 里面没有内容
linux@host~# sed -i "\$a $var" file.txt // 往文件里面添加变量中的数据
linux@host~# cat file.txt // 但文件里面还是没有内容
linux@host~#