[2]
2.1
ls | grep 'hw[0-9][0-9]*.html'
2.2
for i in `ls | grep 'hw[0-9][0-9]*.html'`
do
new=`echo $i | sed 's/html$/txt/'`
mv $i $new
done
Notice that the following two commands:
ls hw*.html
ls hw[0-9]*.html
don't list exactly all the filenames as required because filename
expansion in shell doesn't support full regular expression. E.g.,
* means any string of characters in the shell as opposed to
zero or more repetitions of the previous character in a regular
expression.
[3]
3.4
ypcat passwd | head -10 | awk 'BEGIN{FS=":"}
{
print $1
}
END{print "Total Number of Lines Processed: " NR}'
3.5
print out the average length of the words in /usr/dict/words
3.6
#!/bin/sh
awk '{
if ( length($1) == len ) print $1
}' len=$1 /usr/dict/words
3.7
awk 'BEGIN{OFS="\t";
print "word\t\tindex\tlength\n--------\t------\t-----"
}
$1 ~ /.*'$1'.*/ {
printf "%s\t",$1
if ( length($1) < 8) {printf "\t" }
print index($1, "'$1'"),length($1)
total += length($1)
num+=1
}
END{
print "=======\t\t=====","=====\n" num " words\t\ttotal",total
}
' /usr/dict/words