0

Hi Guys i need to change the below single line string using a shell script

{1:F01NESWSZM0AXXX1111111111} {2:I940BBRUBEBBXXXXN} {3:{108:400MSOG161200FRO}} {4: :20:400MSOG161200FRO :25:1xxxxxxxx65 :28C:7 :60F:D160429EUR423431,51 :61:1604280428DR300001,NONREF//REFABH09 INCOMING F 1 PARMALT ROUTH AFR :62F:D160429EUR423431,51 :64:D160429EUR423431,51 -}

TO

{1:F01NESWSZM0AXXX1111111111} {2:I940BBRUBEBBXXXXN} {3:{108:400MSOG161200FRO}} {4: 
:20:400MSOG161200FRO 
:25:1xxxxxxxx65 
:28C:7 
:60F:D160429EUR423431,51 
:61:1604280428DR300001,NONREF//REFABH09 INCOMING F 1 PARMALT ROUTH AFR 
:62F:D160429EUR423431,51 
:64:D160429EUR423431,51 -}

I was thinking of using sed but the strings are more than 1 when a newline should be added before the character.

The delimiter for a new line are

:20:
:25:
:28C:
:60F:
:64:

How can do this?

2 Answers 2

1

Just use "alternatives" using the \|:

sed 's/\(:\(20\|25\|28C\|60F\|64\):\)/\n\1/g'
5
  • Am not sure where am getting it wrong am using sed 's/(:(20\|25\|28C\|60F\|64):)/\n\1/g' SWZIN7>nick where SWZIN7 is a file with the string to be formatted but it not working May 5, 2016 at 11:39
  • Am doing this on AIX May 5, 2016 at 11:48
  • I'm not sure how sed works on an AIX. Do you have Perl installed?
    – choroba
    May 5, 2016 at 11:49
  • This should work on borne shell right? May 5, 2016 at 11:51
  • sed is an external tool, not part of the shell.
    – choroba
    May 5, 2016 at 11:52
0

I suggest

sed 's/ :/\n:/g' long.txt 
1
  • when i use it it replacing with a n and a newline May 5, 2016 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.