0

In some PHP files, I want to replace "?>\s\t\n\EOF". I test this for search all files where this problem occurred using:

ack "\?\>[\s\n\t]+\z"

I take result but I want replace this by ?>EOF only. I test another command with "sed":

sed 's/?>[\n\t\s]+\z/?>/'

Do you have some tips?

example :

?>  
Herve
  • 127
  • 4
  • You need to explain what you're trying to do more clearly. I suspect you might be trying to remove trailing blanks, tabs and newlines after the last line on a file that contains the close marker for PHP, but it is not clear. Can you show an example of the input files you've got (maybe 4 lines in a minimal example), and the output you desire. As for tips, most versions of `sed` do not recognize Perl regular expressions by default; some have them as an option. – Jonathan Leffler Apr 05 '12 at 14:34
  • What is \s supposed to mean? What \z? – user unknown Apr 05 '12 at 15:08
  • `\z` is EOF? I see, by association with MS-DOS and Ctrl-Z. :) – Kaz Apr 06 '12 at 00:19

1 Answers1

1

ack is perl based, and sed does not recognize things like \z. Use perl:

perl -pe 's/\?\>[\s\n\t]+\z/?>\n/'

Also, \z is not EOF, but merely end of string, so \z will match the end of each line. If you want this to match only at the end of the file, you will need to use something other than \z.

William Pursell
  • 204,365
  • 48
  • 270
  • 300