简体   繁体   中英

Create an aspell style file editing bash script

I'm creating a command line lint tool to run on Linux.

My output currently look like this:

./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

By piping the output into awk '/.\\/ex/{print;}' I can extract just the file names:

./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

I would like to open each of these file in turn and edit them, maybe giving a message to the user with the errors in each file as I open them. Similar to what aspell does.

Is this possible?

With and :

Demo :

在此处输入图片说明

Code:

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

You could try the following bash script:

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

where input.txt is the output from your lint command, and getErr.awk is

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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