[英]Awk to print each file
I have about 50 files in a directory 我的目录中大约有50个文件
Have 有
File1: 1|2|3
File2: 3|4|5
File3: A|B|C
WANT 想
File1: A|1|2|3
File2: A|3|4|5
File3: A|A|B|C
I'll appreciate if anyone can solve it with awk
command. 如果有人可以用awk
命令解决它,我将不胜感激。 I'm open to other solutions in linux. 我对Linux中的其他解决方案持开放态度。 Also, I want to run it once an perform edits on all files in a directory. 此外,我想在对目录中的所有文件执行编辑后运行它。
The solution (see below) I have will require me to run it on each file one at a time and I don't think that's efficient 我拥有的解决方案(请参阅下文)将要求我一次在每个文件上运行它,但我认为这样做效率不高
awk '{print "A|"$0}' File1
Try the below sed command, 试试下面的sed命令,
sed -i 's/^/A|/' file1 file2 file3
To make it work on all the files in the current directory, 为了使其适用于当前目录中的所有文件,
sed -i 's/^/A|/' *
使用GNU awk for -i inplace
:
gawk -i inplace '{print "A|"$0}' file1 file2 file3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.