Page 1 of 1

applying trim function to all the columns in a file

Posted: Thu Dec 04, 2003 9:31 am
by sam2000
I have more than 100 columns in a file and I want to apply TRIM function to all the columns. Is there any quick way of applying this function, instead of calling this function for each column in Transformer stage ???

Thanks

Posted: Thu Dec 04, 2003 9:39 am
by Peytot
Yes, If you change the format of your file with delimiter and the trim done when the field is created.
Else No.

Good luck

Pey

Posted: Thu Dec 04, 2003 10:07 am
by 1stpoint
If you are on unix and, say your input file is pipe '|' delimited, you can very quick use sed to do the replacement:

Code: Select all

PRG=$( basename $0 )

#* Check if file exists, bail if it doesn't.

if [ -f $1 ]; then
   sed -e 's/[ ]*|/|/g' $1
else
   echo "$PRG: Non existant file provided: $1"
   exit 1
fi


Posted: Thu Dec 04, 2003 10:43 am
by Teej
1stpoint wrote:If you are on unix and, say your input file is pipe '|' delimited, you can very quick use sed
This solution only trim the right side of the field. Trim() is capable of eliminating leading along with trailing spaces.

Code: Select all

sed -e 's/[ ]*|[ ]*/|/g' $1
This will do the trick.

Wow, first time I ever used sed...

-T.J.

Posted: Thu Dec 04, 2003 10:48 am
by 1stpoint
I know, usually when we trim it almost always from the right.