Trailing Spaces in Unix

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
purush
Participant
Posts: 16
Joined: Sat Nov 25, 2006 5:34 am
Location: Hyderabad

Trailing Spaces in Unix

Post by purush »

Hi,

My requirement is to read a file. Actually there will be a file in the ftp Common folder. We have a script that will take the file from there and keep it in our project folder. When I'm trying to do a view data...I'm unable to..... :cry: .

I did a VI and saw that there are some trailing spaces[^M] at the end of each line. I also tried by converting it to ascii mode and the ftp'd the file.....but still was helpless........


Please help me if u can suggest me any ......... :idea:

Thanks in Advance
Purush...:)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

^M is not a space character. It is a carriage return, or Ctrl-M, or Char(13). It suggests that this file was generated on a Windows system.

Try using a filter command in the Sequential File stage that uses tr -d to remove the \r characters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
smrutiranjannayak
Participant
Posts: 22
Joined: Mon Apr 02, 2007 4:02 am
Location: MUMBAI
Contact:

This solution is already given.....

Post by smrutiranjannayak »

Hey ,

Use the below command :

when to save ur file in Unix do this :

:%s/ctrlv+m//

means colon then % ,then s then / ,then control v and controll m ,then double slash

enjoy :lol:
Smrutiranjan Nayak
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I think you mean, while in vi, save it as follows, right smrutiranjannayak?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Close. It's a command to remove the ^M characters. Problem is it's not quite right. To enter control characters, you first press Ctrl-V and then the character in question. To get a 'control M' you don't type an 'M' - you press ENTER after the Ctrl-V.

You would do this before saving. Best to get the Sequential File settings correct so the file can be read - there's nothing out of the ordinary here and is perfectly feasible to do. And an ASCII ftp to a UNIX box would have converted any <CR><LF> pairs to plain <LF> characters. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
snt_ds
Premium Member
Premium Member
Posts: 280
Joined: Wed Oct 18, 2006 11:53 am
Location: Pune, India

Re: Trailing Spaces in Unix

Post by snt_ds »

Hi Purush,

I had similer kind of issue, the following script helped me out to remove the carriage return.

if [ $UNAME = "SunOS" ]
then
dos2unix ${SRC_PATHNM}/$FILENM ${INT_PATHNM} $FILENM.dos2unix
grep -v "^$" ${INT_PATHNM}/$FILENM.dos2unix > ${INT_PATHNM}/$FILENM
rm -f ${INT_PATHNM}/$FILENM.dos2unix
exit 0
fi

Thanks,
snt_ds
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: This solution is already given.....

Post by ray.wurlod »

smrutiranjannayak wrote:Hey ,

Use the below command :

when to save ur file in Unix do this :

:%s/ctrlv+m//

means colon then % ,then s then / ,then control v and controll m ,then double slash

enjoy :lol:
Grammatical Note
Ur was a city in ancient Babylon. Please use correct English pronouns such as "your" here. Would you use "ur" in your professional documentation? We believe that DSXchange is a community of professionals.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Cr.Cezon
Participant
Posts: 101
Joined: Mon Mar 05, 2007 4:59 am
Location: Madrid

Post by Cr.Cezon »

Note that in unix the trailing spaces are losted, i think for better performance.
if you don't want to loose these trailing spaces you must insert another caractere (example_ tab) at the end the record.

regards,
Cristina
Post Reply