home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / question / 13199 < prev    next >
Encoding:
Internet Message Format  |  1992-11-10  |  2.3 KB

  1. Path: sparky!uunet!ogicse!decwrl!concert!sas!mozart.unx.sas.com!sasrem
  2. From: sasrem@herald.unx.sas.com (Randy Mullis)
  3. Newsgroups: comp.unix.questions
  4. Subject: sed puzzler
  5. Message-ID: <BxID4C.6Lu@unx.sas.com>
  6. Date: 10 Nov 92 16:14:36 GMT
  7. Article-I.D.: unx.BxID4C.6Lu
  8. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  9. Organization: SAS Institute Inc.
  10. Lines: 65
  11. Originator: sasrem@herald.unx.sas.com
  12. Nntp-Posting-Host: herald.unx.sas.com
  13.  
  14.  
  15. Hi, I would desparately like some help with a sed problem that has been
  16. driving me crazy.  
  17.  
  18. To spare you from having to read the details that follow, here is the 
  19. basic question:  In sed you can use [^\\] to create a match on "not 
  20. backslash".  Is there a way to specify "not \xe"?
  21.  
  22.  
  23. Okay, here are the details. I want a substitution command to substitute
  24. one space for all the material between a start indicator and an end
  25. indicator.
  26.  
  27. The start indicator is a backslash followed by two x's and some
  28. miscellaneous other characters.  The end indicator is a backslash
  29. followed by 'xe'.  The start and end can be on different lines, on the 
  30. same line, or more than one to a line.
  31.  
  32. The program I wrote to do this is:
  33.  
  34. if [ "$#" -eq "0" ]
  35. then
  36.     echo "noindx: arg count error" >&2
  37.     echo "usage: noindx file [...]" >&2
  38.     exit 1
  39. fi
  40.  
  41. for FILE in $@
  42. do
  43.     if [ ! -s $FILE ]
  44.     then
  45.         echo "file \"$FILE\" does not exist" >&2
  46.         continue
  47.     fi
  48.  
  49. sed   '/[^^]\\xx[^ =]*[= ][^\\]*\\xe[ ]*[^$]/b block1
  50.        /\\x[^e]*[= ]/b block2
  51.        /\\xe/b block3
  52.        :block1
  53.            s/\\xx[^ =]*[ =][^\\]*\\xe / /g
  54.        :block2
  55.            /\\xe$/!s/\\xe/&\
  56. /g
  57.        :block3
  58.            /^\\x[^e].*[= ]/!s/\\x[^e]*[= ]/\
  59. &/g
  60. '   $FILE |
  61.  
  62. sed  '  /^\\xx[^ =]*[= ][^\\]*\\xe[ ]*$/d
  63.         /^\\xx[^ =]*[= ]/,/[^\\]*\\xe[ ]*$/d'  > $FILE.new
  64.  
  65. done
  66.  
  67. This seemed to be the answer UNTIL I was told that there may be another
  68. backslash construct between the \xx.. start indicator and the \xe end 
  69. indicator.  This means that I cannot use the [^\\] as a terminating 
  70. condition.  
  71.  
  72. The basic question, then, is this: is there a way in sed to specify
  73. "not (\xe)" as a terminating condition?  Any help would be appreciated.
  74. -- 
  75. ____________________________________________________________
  76. Randy Mullis (sasrem@unx.sas.com)
  77. Systems Administrator, Publications Division
  78. SAS Institute Inc.
  79.