1

我正在创建一个命令行 lint 工具以在 Linux 上运行。

我的输出目前看起来像这样:

./ex4/task6.7/SumOfCubedDigits.java
> Line 15 has inconsistent indenting
> Line 16 has inconsistent indenting
./ex2/task3.2/YearsBeforeRetirement.java
> Line 0 has a curly brace on the end
./ex2/task3.4/YearsBeforeRetirement.java
> Line 0 has a curly brace on the end
./ex2/task3.7/ThreeWeights.java
> Line 18 has inconsistent indenting
> Line 29 has inconsistent indenting
./ex2/task3.7/fourWeightsCoffeeTime/FourWeights.java
> Line 9 has inconsistent indenting
> Line 11 has inconsistent indenting
./ex2/task2.9/Limerick.java
> Line 0 has a curly brace on the end

通过管道输出,awk '/.\/ex/{print;}'我可以只提取文件名:

./ex4/task6.7/SumOfCubedDigits.java
./ex2/task3.2/YearsBeforeRetirement.java
./ex2/task3.4/YearsBeforeRetirement.java
./ex2/task3.7/ThreeWeights.java
./ex2/task3.7/fourWeightsCoffeeTime/FourWeights.java
./ex2/task2.9/Limerick.java

我想依次打开这些文件中的每一个并对其进行编辑,可能会在我打开它们时向用户发送一条消息,其中包含每个文件中的错误。类似于 aspell 所做的。

这可能吗?

4

2 回答 2

1

使用

演示:

在此处输入图像描述

代码:

file=/path/to/file.txt

trap '\rm -f /tmp/out_file' 0 1 2 3 15

if dialog \
    --clear \
    --title "Pick up one of these files" \
    --menu "Files/errors" 80 300 100 $(
        awk '/>/{
            $1=""
            gsub(/ +/, "_", $0)
            arr[k]=arr[k] $0
            next
        }
        {k=$0}
        END{for (a in arr) printf "%s ", a " " arr[a]}
    ' "$file") 2>/tmp/out_file
then
    $EDITOR "$(</tmp/out_file)"
fi
于 2013-10-28T19:53:13.003 回答
0

您可以尝试以下bash脚本:

files=$(awk '/.\/ex/{print;}' input.txt)
for file in $files ; do
    echo "File: "$file
    echo "Errors:"
    awk -vfile=$file -f getErr.awk input.txt
    #open file in editor
done

您的命令input.txt的输出在哪里,并且是lintgetErr.awk

$0 ~ file {f=1; next}
f && /^> Line/ {print;next}
{f=0}
于 2013-10-28T18:48:29.230 回答