|
Posted by Tim Roberts on 11/01/06 06:48
"Anthony Smith" <mrsmithq@hotmail.com> wrote:
>
>I have the need to take a file and remove the trailing white space as
>well as any empty lines... I inherited this script:
>>
>cat $1 | awk -v quote="'" \
> '
> /^[ ]*$/ { next; }
> /^.*[ ]*$/ {
> printf ("%s\n",substr ($0,1,match($0, "[
>]*$")-1));
> next;
> }
> { print $0; }
> '
>I prefer to do it in PHP. Is there a simpler way?
Why would you prefer to do it in PHP? This is exactly what commands like
perl and awk and sed were designed for, not php.
There are, however, simpler ways to do it. For example, this should
replace your entire script:
sed -e 's/[ \t]*$//' -e '/^$/d' $1
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Navigation:
[Reply to this message]
|