You want to use sed and awk for a truly robust solution.
If you need further help, I can dig up examples of doing this. Generally, when I need to do text processing, I turn to perl. However, this can be done in bash, but larger tasks will get ugly in bash.
-Chuck
John H Darrah wrote:
On Mon, 4 Nov 2002, Chad Skinner wrote:Is there a way in a bash script to trim the spaces from the front and end of a variable I have a script that contains the following variable definition BLOCKED_SERVICES="tcp,111,Sun RPC;\ udp,111,Sun RPC;\ tcp,443,Microsoft DS;\ udp,443,Microsoft DS" I am wondering what the simplest method of extracting each of the three elements from each line of the variable. In otherwords, each line is a PROTOCOL, PORT_RANGE, and DESCRIPTION. I have tried a for loop in bash similar to the following. IFS=";" for SERVICE in $BLOCKED_SERVICES do # SEPARATE SERVICE VARIABLES PROTOCOL=`echo $SERVICE | $CUT -f1 -d","` PORT=`echo $SERVICE | $CUT -f2 -d","` MESSAGE=`echo $SERVICE | $CUT -f3 -d","` The problem is that this gives the protocol with the leading spaces and I need to get rid of them. Does anyone know how to do this or have a better solution.How about like this? while read PROTOCOL PORT MESSAGE do echo $PROTOCOL $PORT $MESSAGE done <<-Eod tcp 111 Sun RPC udp 111 Sun RPC tcp 443 Microsoft DS udp 443 Microsoft DS Eod
-- redhat-list mailing list unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list