追加多个文件到一个(awk)
问题描述:
我想将所有文件转储到一个文件。为此,我就是用这个awk脚本(reading.awk)追加多个文件到一个(awk)
BEGIN {
RS = "\n"
filename= "DDL_dump.sql"
flag=1;
}
{
record =$0
if(record == ") ;")
flag = 0;
else if(flag==1)
print record >> filename
}
END {
close(filename)
}
但对于每一个文件,它覆盖追加代替。
试图从与文件相同的文件夹中的bat文件运行此操作。
FOR %%i IN (*.sql) DO awk -f reading.awk %%i
答
看起来你想这样(无壳环):
awk 'FNR==1{f=1} /\) ;/{f=0} f' *.sql > 'DDL_dump.sql'
在多形式说明:
# True for the first line of each file
FNR==1 {
f=1 # Set f(lag)
}
# Once the pattern occurs ...
/\) ;/ {
f=0 # ... reset the (f)lag
}
# As long as the f(lag) is true, print the line.
f
*.sql
是一个shell水珠表达式扩展到当前文件夹中的所有.sql文件,并将p驴友们以awk
作为参数。
> 'DDL_dump.sql'
是将在awk
命令的输出存入DDL_dump.sql外壳输出重定向
错误:'$打印记录...'应该是'打印记录...'我我不确定这是否是原因,因为我没有尝试代码,因为没有样本数据。 –
没有。没有帮助! – codebee
@codebee:请告诉我们你是如何运行这个的 – Guru