如何在第一行前添加一个空行与AWK的文本文件 [英] How to add a blank line before the first line in a text file with awk

查看:1208
本文介绍了如何在第一行前添加一个空行与AWK的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本文件。我想在每个文本文件的第一行前添加一个空行。我怎样才能做到这一点使用awk?


解决方案

我想preFER GNU的sed 此任务:

要在空间添加到文件的开头:

 桑达'1秒/.*/和放大器; /'file.txt的

要在与 .TXT 扩展多个文本文件执行此,并直接进行更改的文件(即覆盖它们),请尝试:

  SED -s -I'1S /.*/和放大器; /* .TXT

要在文件的开头添加一个空行

  sed的'1I \\\\'file.txt的

要在与 .TXT 扩展多个文本文件执行此,并直接进行更改的文件(即覆盖它们),请尝试:

  SED -s -i'1I \\\\'* .TXT

I have some text files. I would like to add a blank line before the first line in each text file. How can I do this with awk?

解决方案

I would prefer GNU sed for this task:

To add a space to the beginning of the file:

sed '1s/.*/ &/' file.txt

To perform this on multiple text files with the .txt extension, and make the changes directly to the files (i.e. overwrite them), try:

sed -s -i '1s/.*/ &/' *.txt

To add a blank line at the beginning of the file:

sed '1i\\' file.txt

To perform this on multiple text files with the .txt extension, and make the changes directly to the files (i.e. overwrite them), try:

sed -s -i '1i\\' *.txt

这篇关于如何在第一行前添加一个空行与AWK的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆