Take the 2-minute tour ×

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 :

share|improve this question
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 5 '12 at 14:34
What is \s supposed to mean? What \z? –  user unknown Apr 5 '12 at 15:08
\s is white space, \z is EOF –  Herve Apr 5 '12 at 15:16
\z is EOF? I see, by association with MS-DOS and Ctrl-Z. :) –  Kaz Apr 6 '12 at 0:19

1 Answer 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.

share|improve this answer
ok thanks, i continue my research –  Herve Apr 6 '12 at 6:55

Your Answer


