formatindock

来自「最经典的分子对结软件」· 代码 · 共 110 行

TXT
110
字号
#!/bin/sh # this script is used to format INDOCK's in a neat fashion# DAG 8/25/94if [ $# -eq 1 ]; then	infile=$1else	infile="INDOCK"fiif [ ! -f $infile ]; then	echo "Sorry, a file called $infile was not found."	echo	echo "Usage: `basename $0` [INDOCK_file_name]"	echo "         where <INDOCK_file_name> defaults to INDOCK if omitted."	exit 1fioutfile=$infile.clean# Now put the INDOCK in neat format, also takes care of spacing problemsecho "Formatting INDOCK..."nawk '# define a function that checks if a character is a letterfunction isLetter(char){letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"i=index(letters,char)return i};# now do the main program{# get first and second character on linefirst=substr($0,1,1);second=substr($0,2,1);if (((first == "#") && (isLetter(first) == 0)) || ($1 ~ /DOCK/))	# Lines not to be modified are those defined as a # followed be	# a NON-LETTER character, including a space.  (in case some 	# keywords are commented out temporarily, we still want to 	# format them).	{	print	}else	{	if (NF >= 2)		{		# We need to locate the value on the line (i.e. 2nd field)		# and format it appropriately (in this case, we only left		# justify all values beginning at column 30).		# The ensuing funny business works as follows:  find the		# position on the line where the value (i.e. 2nd field)		# begins.  But, it is possible that the value may itself		# be contained in the keyword (e.g. when value = "n"), so		# we must avoid make substitutions within the keyword.		# Strategy:  delete the keyword from the line, find		# the starting position of the value in the truncated 		# line, then add back the length of the keyword to simulate		# the true position on the original line.		# the first field on the line is the keyword		keyword=$1		# get the length of the keyword		len=length(keyword)		# copy the input line		line=$0		# delete the keyword on the line		sub(keyword,"",line)		# find where on the line the second field begins		start=index(line,$2)+len		# now extract everything but the first field into the "values"		values=substr($0,start)		# print out the formatted line		printf("%-30s%s\n",keyword,values);		}	else		{		# only one field - dont change anything		print		}	}}' $infile > $outfileechoecho -n "Replace original file with cleaned version? "read yorncase $yorn in        [Yy]*)		mv $outfile $infile                echo "Replaced $infile with cleaned version."                ;;        *)                echo "Leaving original ($infile) untouched."                echo "Cleaned output was put in $outfile."                ;;esac

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?