[英]How to check if “{” begins in separate line in java file using bash script
I have a set of .java
files in one directory. 我在一个目录中有一组
.java
文件。 Now i want to check if the {
(left brace) is beginning a new line or not. 现在,我想检查
{
(左括号)是否开始换行。
For example, 例如,
class Name{
public static void main(String args[])
{
System.out.println("Hello");
}
}
The script has to check how many {
are beginning a new line and how many are not, and give a count. 脚本必须检查有多少
{
正在开始换行,有多少没有开始,并计数。
Use grep -c '^\\s*{' <filename>
to get the number of opening braces "{" that are not preceded by anything else on their line. 使用
grep -c '^\\s*{' <filename>
来获取在其行首没有其他任何内容的开括号“ {”的数量。 This would however also count lines where some text follows a brace. 但是,这还会计算一些文本在大括号后面的行数。 So you might want to use
grep -c '^\\s*{\\s*$'
, which counts lines that only contain a brace (sourounded by arbitrary white-space). 因此,您可能想使用
grep -c '^\\s*{\\s*$'
,它计算仅包含括号的行(由任意空格包围)。
i want to check if the "{" (parenthesis) is beginning from separate line or not.
我想检查“ {”(括号)是否从单独的行开始。
It's not clear exactly what you mean, but if you are simply wanting to know if the "{" char appears in the first position on a line, then "^" in a grep or egrep matches as "starts with". 目前尚不清楚您的意思是什么,但是如果您只是想知道“ {”字符是否出现在一行的第一位置,那么grep或egrep中的“ ^”会匹配为“开头为”。 So grep ^{ *.java would find those lines.
所以grep ^ {* .java将找到这些行。 If that's not what you mean, please change your question text to be specific.
如果这不是您的意思,请更改您的问题文本以具体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.