perl - Rearranging uniq rows in text file -
I have a txt file that looks down from the input file: test.txt
AC 1 CAAAAAC 2 CGSD AC3 FGGB AC1 GHSH AC 2 GHSR AC 1 FGR
My expected output: Amount (Number of rows is of column 3)
AC1 CAFA, GHSH, FGR3 AC2 CGSD, GHSR2AC3FGGB1
I tried with the first awk:
awk '{Line = ""; (I = 2; i & lt; = NF; i ++) Line = line $ i ","; Table [$ 1] = Table [$ 1] for line;} END {(key in table) print key "\ t" table [key];} 'test.txt | Sort
Here there is a little Pearl solution that you may like to command this input file Expect to keep on line as a parameter.
This divides each row of the file into white space and fills the hash % data where the key
ac 1
, ac 2
etc. All keys corresponding to the reference of the arrays of the corresponding values. Once it has been a hash population, it is easy to dump data as necessary.
Use strict; Use warnings; My Information; While (<(my key ($ key, $ val) = partition; Push @ {$ data {$ key}}, $ val; } {My $ list = $ data {$ key}} for my $ key (sort keys% data); Local $ "= ','; printf"% s% s% d \ n ", $ key," @ $ list ", 0 + @ $ list;}
Output
AC1 CAFA, GHSH, FGR3 AC2 CGSD, GHSR2AC3FGGB1
Comments
Post a Comment