in reply to gathering of some elements of a list

Is your data aligned as shown? It might make more sense to treat the records (lines) as having as fixed width fields.

while (<DATA>) { my @parts = unpack('A5 A7 A5 A3 A5 A9 A2 A4 A2 A5 A5 A*', $_); print(join('|', @parts), "\n"); } __DATA__ 0601 3 NORM 2 ALLO XLF753 U 0045 0050 0603 5 NORM 2 ALLO ADR2CG 0430 0438 0604 6 NORM 2 ALLO AF681VC i U 0500 0510 0605 7 NORM 2 ALLO AF651PQ i 0515 0523 0606 8 NORM 2 ALLO AF713BR i 0445 0453 0607 9 NORM 2 ALLO AFR100M i 0520 0533 0609 11 NORM 2 ALLO GJT775 i E 2300 2315 0610 12 NORM 2 ALLO AF661WN i 0450 0500 0500
0601|3|NORM|2|ALLO|XLF753|||U|0045|0050| 0603|5|NORM|2|ALLO|ADR2CG||||0430|0438| 0604|6|NORM|2|ALLO|AF681VC|i||U|0500|0510| 0605|7|NORM|2|ALLO|AF651PQ|i|||0515|0523| 0606|8|NORM|2|ALLO|AF713BR|i|||0445|0453| 0607|9|NORM|2|ALLO|AFR100M|i|||0520|0533| 0609|11|NORM|2|ALLO|GJT775|i|E||2300|2315| 0610|12|NORM|2|ALLO|AF661WN|i|||0450|0500|0500

Replies are listed 'Best First'.
Re^2: gathering of some elements of a list
by steph_bow (Pilgrim) on Jul 30, 2007 at 14:27 UTC

    Dear ikegami
    I would like that my outfile looks like :
    0601|3|NORM|2|ALLO|XLF753|U|0045|0050| 0603|5|NORM|2|ALLO|ADR2CG||0430|0438| 0604|6|NORM|2|ALLO|AF681VC|i U|0500|0510| 0605|7|NORM|2|ALLO|AF651PQ|i|0515|0523| 0606|8|NORM|2|ALLO|AF713BR|i|0445|0453| 0607|9|NORM|2|ALLO|AFR100M|i|0520|0533| 0609|11|NORM|2|ALLO|GJT775|i E|2300|2315| 0610|12|NORM|2|ALLO|AF661WN|i|0450|0500|0500

    So that there is a unique column for i, E, and U and if two both appear on the same line, that they are in the same column.

      Here's a solution that creates the output you've added to the OP using the updated input data. (When making changes to a post, especially if replies relied on the original unchanged data, specify the changes you made by adding "Update:".)

      while (<DATA>) { my @parts = unpack('A5 A7 A5 A3 A5 A9 A8 A5 A*', $_); for ($parts[6]) { s/\s+/ /g; s/^\s//; } print(join(';', @parts), "\n"); }

      or

      while (<DATA>) { my @parts = unpack('A5 A7 A5 A3 A5 A9 A2 A4 A2 A5 A*', $_); my $flags = join ' ', grep length, @parts[6..8]; splice(@parts, 6, 3, $flags); print(join(';', @parts), "\n"); }

      The second version is basically the same as FunkyMonk's, but I do the substitution after extracting the fields.