The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 11-20-2007
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Eek! Forget sed and awk unless you really need regexp - moderns shells are powerful enough:

Code:
#! /bin/bash

line='echo "###Usage: $0 <database1> <database2>"'

line=${line#*<}
DB1=${line%%>*}

line=${line#*<}
DB2=${line%%>*}

printf "\$DB1=$DB1 \$DB2=$DB2\n"

This works in non-ancient versions of bash and pdksh (don't have AT&T ksh handy, but I'd expect it to work there as well.)

This is faster and more elegant, in my not-so-humble opinion