Попытка прочитать атрибуты XML из нескольких файлов и заменить их числом в 1,25 раза больше, чем раньше

Сделать это можно с помощью iwgetidиз пакета wireless_tools:

pacman -S wireless_tools

Затем запустите

iwgetid -r
0
05.05.2021, 07:45
1 ответ

Я решил проблему, реализовав параметр с временным корневым узлом, чтобы сделать его действительным, а затем используя Gizmo, как было предложено. Для тех, кто наткнется на это позже, вот мое решение.

Я загрузил Java-версию Saxon Home Edition , распаковал ее в подпапку «Saxon» и успешно использовал следующий сценарий.

#!/bin/bash

#remove script and generate it with the following lines (that way I only need
#to include my one.sh file)
rm -f script
echo update //@Torque with.*1.25>script
echo save temp_updated.xml method=xml indent=yes>>script

#we do the following to all xml files in the subfolder "classes/engines/"
for filename in classes/engines/*.xml
do
    #cleanup in case they got leftover, which is important for Gizmo,
    #otherwise I get a thousand "Overwrite File" prompts, which is
    #not conducive to automating the process.
    rm -f temp.xml
    rm -f temp_updated.xml

    #make a new temp file, starting with the temporary root element,
    #append the original file and close the root element
    echo "<xml_temp>">temp.xml
    cat $filename>>temp.xml
    echo "</xml_temp>">>temp.xml

    #call Saxon with the correct codepath, start the Gizmo subroutine or whatever
    #take the temporary file as input and "script" as the commands to be executed
    java -cp "Saxon/saxon-he-10.5.jar:Saxon/jline-2.14.6.jar" net.sf.saxon.Gizmo -s:temp.xml -q:script
    #sed -i for inplace editing of the file
    #the first expression '$d' removes the last line (the closing temp root tag)
    #the second impression removes the first line (Gizmo tags on some kind of xml info
    #and the second line, which contains the starting temp root tag
    sed -i -e '$d' -e 1,2d temp_updated.xml

    #I force overwrite the old file with the new and improved xml
    cp -f temp_updated.xml $filename
    #...and clean up after myself
    rm -f temp.xml
    rm -f temp_updated.xml
    rm -f script
done
0
28.07.2021, 11:35

Теги

Похожие вопросы