Replacing Characters

Hi All,

I have a file which is delimeted with the character '. i need to replace this character with the same character and also a new line.

Can anyone please help me with the tr command for this.

Many thanks

Karan

i checked and found tr replaces only one character....i think sed might do it i tried many combinations its not helping???

tr can't replace a single character with a sequence (at least not in the general case). You want sed instead.

sed "s/'/'\\n/g" file

If your sed doesn't understand \n, try with a literal newline. (It looks funny, but you should be able to copy+paste this to your shell prompt, unless you use csh or tcsh.)

sed "s/'/'\\
/g" file

era,

thanks for your help...i tried but they didnt replace it with the new line???

can you please help

replace the ' with a '~
hopefully, you do not have ~ anywhere else in your file
>sed "s/'/'~/g" file

then do the translate function
>tr "~" "\n" file

So, altogether, it could be:

> cat infile
Line 1 is here'Followed by line 2'and ending with line3'
> cat infile | sed "s/'/'~/g"
Line 1 is here'~Followed by line 2'~and ending with line3'~
> cat infile | sed "s/'/'~/g" | tr "~" "\n"
Line 1 is here'
Followed by line 2'
and ending with line3'

try this
cat filename |tr -s "." "\n"

try escape characters

I cannot use the character ~ as this might come in the data.....
Any other suggestions i tried all of the above none seems to work

Hi Era your solution worked fine with using sed "s/'/'\\
/g" file

however i am not sure how to use these two commands in the command

remoteName=ediweb$(date +%m%d%H%M%S).$(cat $localFromDir/$currentFile | tr -d '\012' | tr \' '\012' | grep ^UNB | head -1 | cut -d+ -f6)

can you please let me know how can i replace your command with the one tr \' '\012' mentioned in my above command

thanks

karan

If I grok the above command soup correctly, you want

remoteName=ediweb$(date +%m%d%H%M%S).$(tr -d '\012' <$localFromDir/$currentFile | sed "s/'/'\\
/g" | grep ^UNB | head -1 | cut -d+ -f6)

That's still pretty useless, as you could replace the whole sed | grep | head mess with a single sed script.

remoteName=ediweb$(date +%m%d%H%M%S).$(tr -d '\012' <$localFromDir/$currentFile |
    sed -n "s/\(.*'\)\?\([^']*UNB[^']*'\).*/\1/p;T;q" | cut -d+ -f6)

The cut could probably also be added to the sed script, and the tr might be unnecessary, depending on the input file format.

Can you explain me briefly what exactly the whole sed command that you have written is doing???

thanks

Karan

i tried using the above it didnt run and gave me an error:-

sed:0602-403 then whole command is not a recognised function