Hello
I have had a requirement where I need to move data to a new line based on a text .So basically as soon as it encounters :61: it should move to a new line
Source Data :
:61:D100,74NCH1 :61:D797,50NCH2 :61:D89,38NCHK2 :61:D99,38NCHK12 :61:D79,38NCHK22 :61:D29,38NCHK5
Target Data required :
:61:D100,74NCH1
:61:D797,50NCH2
:61:D89,38NCHK2
:61:D99,38NCHK12
:61:D79,38NCHK22
:61:D29,38NCHK5
Command Used :
sed 's/\([[:space:]]\)\(:61:\)/\1\n\2/g' file1 > file2
Issues faced :
1) sometimes the last record is missed (like the Record:61:D29,38NCHK5 will not show up in the target)
2) One of the source entries will get duplicated in the target
Can somebody please suggest any other command or any modifications
Thanks
At the end of that first line is /<space>:/\<return>:/g
If the :61: is a required break character set, and not just space-colon, you would type /<space>:61:/\<return>:61:/ to get the required effect. If it's really just the space that needs to be replaced with a newline, which appears to be the case in your trial dataset, try the tr command. man tr.
I can't reproduce either issue, command applied to source data yields exactly target data required.
Pls. post a data set that produces the issues. BTW, is the space in front of the <new line> really required?