#!/bin/bash

PWD= `pwd` > /dev/null 2>&1
File=`ls $PWD|grep txt`

for i in $File
do
    sed -i '/^Q:/,/^A:/ { /^$/d }' $i
    sed -i '/information is incomplete\|No content to extract\|provide the ticket content\|provided ticket content\|No QA pairs\|given ticket content/d' $i
    sed -i -E '/^Q.*([0-9]{1,3}\.){3}[0-9]{1,3}/{N;d;}' $i
    sed -i "$(grep -n -E '^A.*(([0-9]{1,3}\.){3}[0-9]{1,3})' $i | cut -d: -f1 | awk '{print $1-1 "," $1 "d"}' | tr '\n' ';')" $i
    sed -i '/^Q.*cloudclusters\.net/{N;d;}' $i
    sed -i "$(grep -n -E '^A.*cloudclusters\.net' $i | cut -d: -f1 | awk '{print $1-1 "," $1 "d"}' | tr '\n' ';')" $i
    sed -i '/cloudclusters\.net/d' $i
    sed -i -e '/^Q.*[一-龥]/{N;d;}' $i
    tac $i | awk '/^A.*[一-龥]/ {getline; next} 1' | tac > tmp.txt && mv tmp.txt $i
    sed -i '/[一-龥]/d' $i
    sed -i -E '/\b([0-9]{1,3}\.){3}[0-9]{1,3}\b/d' $i
    sed -i '/^$/{N;/^\n$/D}' $i
done
