Operating System - HP-UX
1832009 Members
3104 Online
110034 Solutions
New Discussion

replace any character with CR

 
SOLVED
Go to solution
Stoicho Valkov
Advisor

replace any character with CR

I have a file like:
123;456;789
how can i replace ";" with carrige return or new line and result should be like:
123
456
789
Can i use sed or other simple command? And how?
Text editor
6 REPLIES 6
curt larson_1
Honored Contributor
Solution

Re: replace any character with CR

cat $file | tr ";" "\012" > $newfile
T G Manikandan
Honored Contributor

Re: replace any character with CR

#cat |tr -s ";" "\n" >/tmp/
Sergejs Svitnevs
Honored Contributor

Re: replace any character with CR

---oldfile---
123;456;789

Try to execute this command:
# sed 's/;/#/g' oldfile | tr '#' '\012' >newfile

Result:
---newfile---
123
456
789

Regards,
Sergejs



Umapathy S
Honored Contributor

Re: replace any character with CR

You can also do it in vi.
open vi and the type in command line
:%s:;:^M:g
Where ^M is Ctrl+V, Ctrl+M.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Brian Bergstrand
Honored Contributor

Re: replace any character with CR

Or perl

cat | perl -pi -e "s/;/\n/go"

HTH.
Steven Sim Kok Leong
Honored Contributor

Re: replace any character with CR

Hi,

Just for kicks, here's another way if you don't wish to use any of "\n" or "\012":

# for i in `sed 's/;/ /g' file`;do echo $i;done > parsed_file

Hope this helps. Regards.

Steven Sim Kok Leong