Bash script to check for final closing /data xml tag in file

Bash script to check for final closing </data> xml tag in file:

if [ -f file.xml ]
then
    # if grep -1iq '</data>' file.xml    # simplest syntax
    # if tac file.xml | grep -1iq '</data>'   # faster syntax (tac is reverse cat)
    if tail -100 file.xml | grep -1iq '</data>'   # fastest syntax, assumes at most 100 trailing lines of whitespace/etc. at end of file.
    then
        echo file ready to be loaded
        # code to load and archive file here
    else
        echo file partially transferred, so no action taken.
    fi
else
    echo file not yet transferred, so no action taken.
fi

This could be put into an infinite loop:

while :
do
    # code to do stuff here
    sleep 1  # sleep for 1 second before checking again, to avoid wasting cpu.
done
June 23, 2015

  • Another Difference :replace function rpaceles a sequence of characters into another sequence of characterstranslate function also rpaceles a sequence of characters to other sequence of character,But the main difference is it rpaceles character by character.And it rpaceles a single character at a time.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *