$ i=10 && while [ $i -ne 0 ] ; do ; od -vAn -N1 -tu4 < /dev/random ; i=`expr $i - 1` ; done | tr -d ' ' | sort -n | uniq > ~/temp/randnums.txt $ cat ~/temp/randnums.txt 1 13 62 64 114 137 210 240 253 $ cat ~/temp/randnums.txt | awk BEGIN{'FS=","}{print $1}' | awk 'BEGIN{pre=0;}{if(pre+1<$1){for(i=pre+1;i<$1;i++){print "*"i"*"}}{print $1}pre=$1;}' | head 1 *2* *3* *4* *5* *6* *7* *8* *9* *10* *11* *12* 13 *14* *15* *16* *17* *18* *19* *20*取りあえずコマンドにしてみる。
$ cat ~/temp/randnums.txt | toothless | head -n 15 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17ソースはこちら
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# toothless | |
VALUE_START_NUMBER=0 | |
while getopts hs: OPT | |
do | |
case $OPT in | |
"s" ) VALUE_START_NUMBER="$OPTARGS" ;; | |
"h" ) echo 'Usage: toothless [-s] <file>'; exit 0 ;; | |
esac | |
done | |
cat $1 | awk 'BEGIN{pre='$VALUE_START_NUMBER';}{if(pre+1<$1){for(i=pre+1;i<$1;i++){skip=0;print i;}}{skip=!skip}pre=$1;}' |
おまけ
- ライフゲーム by awk: いつも orz な ふぶき さん
- AWK Users JP :: 日本の AWK ユーザのためのハブサイト
- The GAWK Manual - Table of Contents
基本的にこのページは全て awk で記述していく。awk/sedいいですよねー面白いですよねー。もっとちゃんとやってみたい。
0 件のコメント:
コメントを投稿