home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!decwrl!concert!sas!mozart.unx.sas.com!sasrem
- From: sasrem@herald.unx.sas.com (Randy Mullis)
- Newsgroups: comp.unix.questions
- Subject: sed puzzler
- Message-ID: <BxID4C.6Lu@unx.sas.com>
- Date: 10 Nov 92 16:14:36 GMT
- Article-I.D.: unx.BxID4C.6Lu
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Organization: SAS Institute Inc.
- Lines: 65
- Originator: sasrem@herald.unx.sas.com
- Nntp-Posting-Host: herald.unx.sas.com
-
-
- Hi, I would desparately like some help with a sed problem that has been
- driving me crazy.
-
- To spare you from having to read the details that follow, here is the
- basic question: In sed you can use [^\\] to create a match on "not
- backslash". Is there a way to specify "not \xe"?
-
-
- Okay, here are the details. I want a substitution command to substitute
- one space for all the material between a start indicator and an end
- indicator.
-
- The start indicator is a backslash followed by two x's and some
- miscellaneous other characters. The end indicator is a backslash
- followed by 'xe'. The start and end can be on different lines, on the
- same line, or more than one to a line.
-
- The program I wrote to do this is:
-
- if [ "$#" -eq "0" ]
- then
- echo "noindx: arg count error" >&2
- echo "usage: noindx file [...]" >&2
- exit 1
- fi
-
- for FILE in $@
- do
- if [ ! -s $FILE ]
- then
- echo "file \"$FILE\" does not exist" >&2
- continue
- fi
-
- sed '/[^^]\\xx[^ =]*[= ][^\\]*\\xe[ ]*[^$]/b block1
- /\\x[^e]*[= ]/b block2
- /\\xe/b block3
- :block1
- s/\\xx[^ =]*[ =][^\\]*\\xe / /g
- :block2
- /\\xe$/!s/\\xe/&\
- /g
- :block3
- /^\\x[^e].*[= ]/!s/\\x[^e]*[= ]/\
- &/g
- ' $FILE |
-
- sed ' /^\\xx[^ =]*[= ][^\\]*\\xe[ ]*$/d
- /^\\xx[^ =]*[= ]/,/[^\\]*\\xe[ ]*$/d' > $FILE.new
-
- done
-
- This seemed to be the answer UNTIL I was told that there may be another
- backslash construct between the \xx.. start indicator and the \xe end
- indicator. This means that I cannot use the [^\\] as a terminating
- condition.
-
- The basic question, then, is this: is there a way in sed to specify
- "not (\xe)" as a terminating condition? Any help would be appreciated.
- --
- ____________________________________________________________
- Randy Mullis (sasrem@unx.sas.com)
- Systems Administrator, Publications Division
- SAS Institute Inc.
-