|
楼主 |
发表于 2003-8-11 09:25:06
|
显示全部楼层
awk '{print ; if (NF != 0) print ""}' infile > outfile
在这行中,print; 代表输出什么?
if (NF!=0)是否指不是空行的行?
print"" 指的又是输出什么?
这些是从这里copy过来的。
For example, suppose I want to turn a document with single-spacing into a document with double-spacing. I could easily do that with the following Awk program:
awk '{print ; print ""}' infile > outfile
Notice how single-quotes (' ') are used to allow using double-quotes (" ") within the Awk expression. This "hides" special characters from the shell you are using. You could also do this as follows:
awk "{print ; print \"\"}" infile > outfile
-- but the single-quote method is simpler.
This program does what it supposed to, but it also doubles every blank line in the input file, which leaves a lot of empty space in the output. That's easy to fix, just tell Awk to print an extra blank line if the current line is not blank:
awk '{print ; if (NF != 0) print ""}' infile > outfile |
|