简体   繁体   English

awk,^反斜杠不是最后一个字符在线

[英]Awk, ^ backslash not last character on line

I am trying to use gawk in windows to parse a directory which contains CSV files for the blank rows in the second column in each file. 我试图在Windows中使用gawk来解析包含每个文件的第二列中的空行的CSV文件的目录。 I want to take the whole row where the the 2nd column is blank from ALL the source files and output to a csv. 我想从所有源文件中取出第二列为空的整行,并输出到csv。 .. what I have so far is below. ..到目前为止我所拥有的是什么。

I am sure this has to do with properly escaping the single quotes, I've tried using ^ and \\ to no avail. 我确信这与正确转义单引号有关,我尝试使用^\\无效。 Thanks for any tips. 谢谢你的任何提示。

awk -F, \'!length$2\' *.csv > output.csv 

Thanks to Etan Reisner and HuStmpHrrr I have it working now. 感谢Etan Reisner和HuStmpHrrr,我现在正在努力。 If you folks want to post answers I can mark them so that you get reputation points. 如果你们想要发布答案,我可以对它们进行标记,以便获得声望点。 Your hints pointed me in the right direction. 你的提示指出了我正确的方向。 I now have all the rows with a blank 2nd row in one file. 我现在所有的行都在一个文件中有一个空白的第二行。 The final working version of the command in my case is : 在我的情况下,命令的最终工作版本是:

awk -F, !length($2) *.csv > output.csv    //Works ( in windows)
  • I am not sure why my answer was edited, but the string above doen`t work when you enclose it in single quotes. 我不确定为什么我的答案被编辑了,但是当你用单引号括起来时,上面的字符串会起作用。

    awk -F, '!length($2)' *.csv > output.csv //Doesn`t Work (in windows) awk -F,'!length($ 2)'* .csv> output.csv //不工作(在windows中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM