1753691 Members
5378 Online
108799 Solutions
New Discussion юеВ

Text search and replace

 
SOLVED
Go to solution
Christian Laurin
New Member

Text search and replace

I receive every day a text X12 file of 1 line which includes approx 1000 characters.

Here's an extract:
ST*997*0222^AK1*IN*000000540^AK2*810*000015314^AK5*A^AK2*810*000015315^AK ...

How can I replace all the ^ by a line feed automatically with a script or a unix command ?

Thanks for your help.
4 REPLIES 4
John Poff
Honored Contributor
Solution

Re: Text search and replace

Hi,

Something like this might work, if your file is named X12:

tr '^' '\n' X12 >X12.new

which will put the contents in X12.new for you.

JP
John Poff
Honored Contributor

Re: Text search and replace

Oops. I missed a < in my post. Try it like this instead:

tr '^' '\n' X12.new


JP
S.K. Chan
Honored Contributor

Re: Text search and replace

OR from your shell prompt ..
$ sed 's/\^/ \
> /g' X12 > X12.clean
H.Merijn Brand (procura
Honored Contributor

Re: Text search and replace

in-line change:

# perl -pi -e 's/\^/\n/g' x12.txt

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn