From: Dan Mercer on

"William Park" <opengeometry(a)yahoo.ca> wrote in message news:5202b$43617e07$d8fea14c$3893(a)PRIMUS.CA...
: Dan Mercer <dmercer(a)mn.rr.com> wrote:
: > "William Park" <opengeometry(a)yahoo.ca> wrote in message news:f2abd$43603ea4$d8fe9d17$6594(a)PRIMUS.CA...
: > : Giacomo <a(a)b.cde> wrote:
: > : > asdasd 123 asd 191991 1234
: > : > lijoioi 4567 asdi 67567 iojoii
: > : >
: > : > For n=4 the result for each line must be 1234 e 4567.
: > :
: > : a='asdasd 123 asd 191991 1234 lijoioi 4567 asdi 67567 iojoii'
: > : RE='\<[0-9]{4}\>'
: > : echo "${a|+$RE}"
: >
: > This can be down in the shell. Assuming lines containing only lower case letters and
: > numbers:
: >
: > ifs=$IFS
: > IFS="${IFS}abcdefghijklmnopqrstuvwxyz"
: > while read line
: > do
: > IFS=$ifs
: > set -- $line
: > IFS=$ifs
: > set -- $*
: > for i
: > do
: > ((${#i} == 4)) && echo "$i"
: > done
: > done
: >
: > Now, this isn't the efficient way to do it. That would probably be
: > best done in perl.
:
: Interesting approach. I would probably do it as
: for i in `tr -c '0-9' ' ' < file`; do
: [ ${#i} -eq 4 ] && echo $i
: done
: or if there is lots of repetition,
: func()
: {
: [ ${#1} -eq 4 ]
: }
: set -- `tr -c '0-9' ' ' < file`
: echo ${@|?func}

But the challenge is NOT to invoke external programs (;-)

Dan Mercer

:
: --
: William Park <opengeometry(a)yahoo.ca>, Toronto, Canada
: ThinFlash: Linux thin-client on USB key (flash) drive
: http://home.eol.ca/~parkw/thinflash.html
: BashDiff: Super Bash shell
: http://freshmeat.net/projects/bashdiff/