applying trim function to all the columns in a file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sam2000
Premium Member
Premium Member
Posts: 1
Joined: Thu Dec 04, 2003 9:21 am
Location: **********

applying trim function to all the columns in a file

Post 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
Peytot
Participant
Posts: 145
Joined: Wed Jun 04, 2003 7:56 am
Location: France

Post 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
1stpoint
Participant
Posts: 165
Joined: Thu Nov 13, 2003 2:10 pm
Contact:

Post 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

Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post 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.
Developer of DataStage Parallel Engine (Orchestrate).
1stpoint
Participant
Posts: 165
Joined: Thu Nov 13, 2003 2:10 pm
Contact:

Post by 1stpoint »

I know, usually when we trim it almost always from the right.
Post Reply