
02-07-2009, 09:09 AM
|
|
Member
User
|
|
Join Date: May 2009
Posts: 93
Thanks: 0
Thanked 16 Times in 16 Posts
Rep Power: 3
|
|
Quote:
Originally Posted by nixcraft
Try the following:
Code:
#!/bin/bash
INPUT=$1
usage(){
echo "Usage: $0 input.txt"
exit 1
}
die(){
echo "$@"
exit 2
}
[ $# -ne 2 ] && usage
[ ! -f $INPUT ] && die "File $INPUT does not exist!"
|
That will fail if $INPUT contains spaces or is empty.
Code:
[ ! -f "$INPUT" ] && die "File $INPUT does not exist!"
Quote:
Code:
while read line
do
echo "$line" | grep -o . | sort -n |tr -d '\n'; echo ""
|
That can fail because most versions of grep so not have an -o option. Use
sed instead.
Code:
echo "$line" | sed 's/./&\
/g' | sort | tr -d '\n'; echo ""
(sort doesn't need the -n option.)
That will fail if $INPUT contains spaces.
|