[HPADM] SUMMARY: ksh, IFS, and backslash

From: Rick Greene (RGreene@rbinc.com)
Date: Fri Jun 27 2003 - 14:12:28 EDT


I love sending out a message just before a meeting, and having tons of answers when I get back.

Thanks to:
Bill Thompson
Gary Paveza
David Lodge
Daniel Brown
Christopher Schroen
Fidel Ramirez
Tom Swigg

I get several renditions of using awk, some sed suggestions, and a couple using some shell built-ins I'd not seen before. Bill Thompson gave a very precise example and description:

> LINE="outbox/08925485US00\200306131322.out.sent"
> TMP=${LINE##*\\}
> NUMBER=${TMP%%\.*}
>
> The part between the backslash (\) and the ".out" will be in $NUMBER
>
> This is very fast as the "##" and "%%" operators are internal to ksh (e.g.:
> you don't have to fork another process like you do with "set").

This got me exactly what I needed, even to stripping off the .out.sent for me. Anyone want the awk or sed ideas, let me know and I'll send those privately...I think the above was the best answer.

Thanks all!

-----Original Message-----
From: Rick Greene
Sent: Friday, June 27, 2003 12:56 PM
To: Hpuxadmin (E-mail)
Subject: [HPADM] ksh, IFS, and backslash

Ok, I can't find anything in the archives, and things I've tried from "man ksh" hasn't helped.

I have a string like this: outbox/08925485US00\200306131322.out.sent

I'm trying to split it out so I get the part between the \ and the .out. I've tried:

IFS=\\ ; set - $line ; unset IFS
IFS="\" ; set - $line ; unset IFS
IFS="\\" ; set - $line ; unset IFS

$line contains the above string, what I want should be in $2, along with the .out.sent, which I can clean later. The second version didn't work at all, as I expected...it just quoted out the quote, throwing the script into conniptions.

Any ideas?

Rick Greene
System & Database Administrator
R&B Inc.
3400 E Walnut Street
Colmar PA 18915
215-712-5171

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)
--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:30 EDT