#!/bin/bash # 20250207 Durtal cleanscan.sh version 2 # Be sure to use the following format: ./cleanscan.sh filename # The following two commands clean out the messages from the server # the -i option ensures that operation occurs "in place" in the file. # The dot (.) represents any character and the asterix repeats only # to the end of the line because sed is a "line editor". Basically, # sed won't print the lines beginning with "3Sorry" or "Error". Not # printing is faster than deleting. sed -n -i '/3Sorry.*/!p' $1 sed -n -i '/Error.*/!p' $1 # If a line has a name that is followed by a blank line, the follow awk # script removes both the lines while ensuring that the final line # gets printed even if it is not part of a match pair. "prev" is # a variable to hold the current line before moving to the next. awk 'NR==1 {prev=$0; next} prev ~ /^[^ ]+$/ && $0 == "" {prev=""; next} {if (prev != "") print prev; prev=$0} END {if (prev != "") print prev }' $1 > temp.txt && mv temp.txt $1