创建一个aspell样式文件编辑bash脚本

时间:2013-10-27 13:59:55

标签: linux bash awk lint

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

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

./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的相似。

这可能吗?

2 个答案:

答案 0 :(得分:1)

演示:

enter image description here

代码:

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

答案 1 :(得分: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.txtlint命令的输出,而getErr.awk

$0 ~ file {f=1; next}
f && /^> Line/ {print;next}
{f=0}