Filter and migrate data from row to column

Hello Experts,
I am new in scripting. I would like to filter and migrate data from row to column by awk. Thanks in advance.

For example
FileA

  abc
  1
  2
  3
  Xyz3
  4
  1
  5
  bcd1
 

Output :

 Abc      1    2    3
 Xyz3     4    1    5
 bcd1     3    5    6

Try:

awk '{ORS=NR%4?FS:RS}1' file

Thanks Franlin52, it's working fine if data is according to fileA but if FileA like
FileA

abc
1
2
3
5
9
10
Xyz3
4
1
5
3
bcd1
4
1

And need output like

Output :

Abc	1    2   3  5   9  10
Xyz3	4    1   5  3
bcd1  3    5

This should work as your sample file...

awk '{printf ($0 ~ /^[A-Za-z]/?RS $0:FS $0)}' infile
1 Like

G8 malcomex999 and Thanks to malcomex999 & Franklin52 .

small more help....can you explain me in few words ....I understand only this

$0 ~ /^[A-Za-z]/?RS

user for search strings and Record Separator but don't understand $0:FS $0

The record sperator RS is missing for the last record.

awk '{printf "%s" ($0 ~ /^[A-Za-z]/?RS $0:FS $0)} END { print RS }' infile

Using printf without format may give an error if printed data contains % sequence.

From Franklin code :

awk '{ORS=/^[A-Za-Z]/NR%4?FS:RS}1' file

Jean-Pierre.

1 Like