Removing \n char in the field

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
senthilt1
Participant
Posts: 134
Joined: Mon Nov 19, 2007 2:17 am

Removing \n char in the field

Post by senthilt1 »

Hi Friends,

I want to replace the char \n with "" from my inp data. I tried it using the convert function. But it takes the unix end of line as \n and replace with " ".

Inp Data: qwerbv\nqewtt\n

Required O\P data: qwerbvqewtt

I tried using the external filter with sed 's/\\n/ /'. its not working out.

Please let me know abt this.

Thanks,

Senthil P
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

convert(char(10),'',In.String)
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

When you say you get "\n" in the input do you mean the actual string "\n" or the line feed character. If you want to remove line feeds then what Arndw says should work for you. If you are trying to remove the literal "\n" from your input string then you can escape the backslash while using convert to get the desired output.

Code: Select all

Convert("\\n","",link.column)
The above code should do the trick.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Wait a minute, I don't know what I was thinking :oops:

Convert replaces all the characters present in the first argument with the second argument. So the above code would also remove "n"s and "\"s from your string which is not what you want. You can use Ereplace to do this, But since your's is a parallel job you won't be able use Ereplace (There is parallel routine on Ereplace posted in DSXchange though..)

You can create a simple unix script which would replace the offending "\n" with empty string in a before job routine and then process it.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Yuo don't need ereplace, just convert. Ereplace functionality replaces one string with another and isn't required here.
senthilt1
Participant
Posts: 134
Joined: Mon Nov 19, 2007 2:17 am

Post by senthilt1 »

Thanks Arndw and Minhajuddin,

Convert function replaces all the characters - as Minhajuddin said. So i should not use Convert funtion for my case. we can easily do this thro unix, but wont there be any other way to replace the literal \n with " " thro Datastage?

Please let me know if there is anything,

Thanks,

Senthil P
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Hello senthilt1, what part of my first post didn't work?
senthilt1
Participant
Posts: 134
Joined: Mon Nov 19, 2007 2:17 am

Post by senthilt1 »

Hi Arndw,

I tried with the ur approach convert(char(10),'',In.String) , But it is not resolving my problem. it gives the output as it is in the input.

Eg:

Inp data: Exce\nllent
O/P Data: Exce\nllent

Theres no change in the output. Seems it works for the line feed character.

Thanks ,

Senthil P
iDomz
Participant
Posts: 81
Joined: Wed Jul 25, 2007 5:25 am
Location: London

Post by iDomz »

If you need to replace the literal string(i.e if it is not a linefeed) '\n', then you need the ereplace equivalent. Dsguru2b has a version on this forum (there is also one I wrote, but it is pretty much untested, so I don't reccomend it)

You can try sed 's,\\n, ,g'

Sed can basically use any char after the first command. So if you have your \s and /s messing things up, just use any other character as your regex delimter.

Regards,
D

Edited as I missed a \
Last edited by iDomz on Thu Jun 05, 2008 4:03 am, edited 1 time in total.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Ok, I have misunderstood your problem. Your real question is "how do I change the string '\n' to a single space?"

One answer is to use a filter of "sed 's/\\n/ /'" in your sequential file stage, as you have already mentioned in your first post. I just wrote a small test job and can confirm that this filter works correctly.
senthilt1
Participant
Posts: 134
Joined: Mon Nov 19, 2007 2:17 am

Post by senthilt1 »

Thanks Arndw for your support.

Sorry if my question was not clear.

I used Sed in seq file filter options. Its working good.


Thanks,

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

Post by ray.wurlod »

Then perhaps you could mark this thread as Resolved.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply