# renum2.sh Renumbers a bunch of sequences # that are already formatted. Skips lines that don't begin with % # Uses file "next" in hisdir as source for new numbers # The single argument is the input file name # Note to myself: remember to maintain the link # ln renum2.sh /usr/njas/wwwfiles/sequences/renum2.sh.txt # Last modified Apr 11 1998 # Comments revised Nov 02 2002 # If you download this from my web page, it is important to # use the SOURCE FILE. DON'T mouse it off the screen # because many of the characters will not be visible. # Call this file renum2.sh (not renum2.sh.txt) # Specify the file with list of free A-numbers. # This file should contain one A-number # per line, e.g. A071234 / A071235 / A071236 / ... # and end with a line saying LASTLINE next=$HOME/gauss/hisdir/next # Specify version of awk AWK=/bin/gawk # check # of argts if [ "$#" -ne 1 ] then echo "Incorrect no of arguments. Usage: renum2.sh infile >out " exit 1 fi # Check "next" contains "LASTLINE" if `grep LASTLINE $next >/dev/null` then : else echo "$next does not contain LASTLINE" exit 1 fi # input "next" and input file to awk (removing trailing blanks on the way) cat $next $1 | sed 's/ *$//' | $AWK ' # read the free numbers BEGIN { loading = 1; old = 0; me = 0 } loading == 1 && $1 != "LASTLINE" { new[NR] = $1 } $1 ~ /LASTLINE/ { loading = 0 count = 0 last = "" flags = 0 next } # edit the sequences # reached start of new sequence, so update things and print newline: # and (at a %I line) print the new %I line loading == 0 && $1 ~ /%I/ { printf("\n"); count = count + 1 ; old = $2 me = new[count] dict[old] = me before[count] = old after[count] = me $2 = me print last = "I" next } # edit each sequence line and print it loading == 0 && $0 ~ /^%/ { for (id in dict) if (id > 0) gsub(id,dict[id]); last = $1; sub("^.", "", last) print } # any suspicious non-% lines in the middle of a sequence? loading == 0 && $0 !~ /^%/ && last == "S" { print "WARNING: suspicious non% line!"; flags++; print; next; } loading == 0 && $0 !~ /^%/ && last == "T" { print "WARNING: suspicious non% line!"; flags++; print; next; } loading == 0 && $0 !~ /^%/ && last == "U" { print "WARNING: suspicious non% line!"; flags++; print; next; } loading == 0 && $0 !~ /^%/ && last == "N" { print "WARNING: suspicious non% line!"; flags++; print; next; } loading == 0 && $0 !~ /^%/ && last == "F" { print "WARNING: suspicious non% line!"; flags++; print; next; } loading == 0 && $0 !~ /^%/ && last == "D" { print "WARNING: suspicious non% line!"; flags++; print; next; } END { printf("\n") print "Changed", count, "sequences:" for (i = 1; i <= count; i++) print before[i], "to", after[i]; print "Should now delete first", count, "lines of gauss/hisdir/next" print "There were ",flags, "WARNING flags" } ' | sed '1d'