Operating System - HP-UX
1838196 Members
3912 Online
110125 Solutions
New Discussion

Regular Expression Question

 
SOLVED
Go to solution
Paul Murray_4
Frequent Advisor

Regular Expression Question

Hi All,

I've got a rather large shell script written in ksh, but I need to make a small modification to pick up a regular expression.

The requirement is to match either wordA or wordB in an "ls" command, but the expression that works in Posix, doesn't seem to work in ksh.

The Posix expression is:-

$ ls -l {FULL,INCR}BACKUP.log

Does anyone know an equiv. for ksh ???

(Thanks in advance for any/all help!!)

Rgds,
Paul.

Hey, nobody knows EVERYthing !!!
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: Regular Expression Question

Paul,

I'm not known for my shell scripting, so take this with a grain of salt:

How about:

ls -l [FI][UN][LC][LR]BACKUP.log

?

Does that give you what you want?


Pete


Pete
Bernhard Mueller
Honored Contributor

Re: Regular Expression Question

Paul,

why not use grep?

ls -l | grep -e 'BACKUP.log$' -e 'FULL|INCR'

(not *exactly* yours but maybe you like this better:

ls -l *BACKUP.log | grep -e 'FULL|INCR'

or really exact and only:
ls -l | grep -e FULLBACKUP.log -e INCRBACKUP.log

Regards,
Bernhard
Leif Halvarsson_2
Honored Contributor
Solution

Re: Regular Expression Question

Hi,
Try (in ksh):
ls -l ?(FULL|INC)BACKUP.log
James R. Ferguson
Acclaimed Contributor

Re: Regular Expression Question

Hi Paul:

Leif's suggestion works.

Here are two other alternatives, too:

(1) Use the standard Posix shell ('/usr/bin/sh'). It is really a superset of the Korn (ksh88) shell as provided with HP-UX.

(2) Instead of the 1988 version of Korn, use the 1993 version. You should find it as '/usr/dt/bin/dtksh'.

Regards!

...JRF...
Jean-Luc Oudart
Honored Contributor

Re: Regular Expression Question

call the posix shell for this part only :

....
/usr/bin/sh "ls -l {FULL,INCR}BACKUP.log"
....

Rgds,
JL
fiat lux
Paul Murray_4
Frequent Advisor

Re: Regular Expression Question

Thanks to all for your help (points have been awarded !!).

Leif's answer has provided exactly what I needed - many thanks !!!

Hey, nobody knows EVERYthing !!!