Arrange values of a column in row

HI,

I need to arrange values of a colum in row.

e.g.

input file :

Alpha<>123
AAAA<>6754
Beta<>456
BBBB<>63784
CCC<>783
Gama<>789
Alpha<>555
AAAA<>6754
BBBB<>63784
Beta<>666
CCC<>783
Gama<>888
.
.
.

desired output:

Alpha<>123 | Beta<>456 | Gama<>789 |
Alpha<>555 | Beta<>666 | Gama<>888 |
.
.
.

Thanks in advance
Archer

something like :

#  paste - - - < infile
Alpha<>123      AAAA<>6754      Beta<>456
BBBB<>63784     CCC<>783        Gama<>789
Alpha<>555      AAAA<>6754      BBBB<>63784
Beta<>666       CCC<>783        Gama<>888

or 

#  paste -d"|" - - - < infile
Alpha<>123|AAAA<>6754|Beta<>456
BBBB<>63784|CCC<>783|Gama<>789
Alpha<>555|AAAA<>6754|BBBB<>63784
Beta<>666|CCC<>783|Gama<>888

what you're after ? Or are you only wanting specific lines/regexps ?

what is exact format of infile / outfile

HTH

@The_Archer: What happend to "AAA" , "BBB" and "CCC" columns ?

Like this?

paste -d'|' <(grep Alpha input) <(grep Beta input) <(grep Gama input)

This will help your requirement :slight_smile:

sort input.txt|sed 's/^./& /g'|nawk '{if(NR!=1 && $1 != prev) {ORS="\n";print;prev=$1} else {ORS=":";print;prev=$1}}'|sed 's/ //g'

Thanks
Sha

"AAA" , "BBB" and "CCC" columns values need to be discard

---------- Post updated at 06:40 PM ---------- Previous update was at 06:39 PM ----------

Thanks Sha

but i donot need to sort the coloum ,
as every Alpha is associated with its beta & Gamma under it

How about this

 
perl -0ne 'print "$1 | $2 | $3 |\n" while (/(Alpha<>\d+).*?(Beta<>\d+).*?(Gama<>\d+).*?/sg)' input
awk '/Alpha/ { a=$0;next } /Beta/ { a=a"|"$0;next } /Gama/ {a=a"|"$0; print a}' input_file

I am expecting there will be a matching "Gama" in the end and the order also wil be remain same

Open logic Shell version. Assuming you have shell which supports echo with \c (no linefeed). If not, use "echo -n" or printf.

cat file.txt | while read line
do
        case "$line" in
        Alpha*) echo "${line} | \c"
                ;;
        Beta*)  echo "${line} | \c"
                ;;
        Gama*)  echo "${line} |"
                ;;
        esac
done


Alpha<>123 | Beta<>456 | Gama<>789 |
Alpha<>555 | Beta<>666 | Gama<>888 |

use below.

gawk '/Alpha/||/Beta/{s= s ? s"|"$0 : $0 }/Gama/{print s"|"$0 ; s="" }' infile.txt
o/p:-
Alpha<>123|Beta<>456|Gama<>789
Alpha<>555|Beta<>666|Gama<>888

:slight_smile: