If I understood what you want then you should use xargs and awk commands:
xargs -n3 < your_file.txt | awk '{gsub(/(Name|Admin|Oper)>/,""); print $1","$2","$3}' | awk -F',' --file script.awk
Where script.awk contains this:
#! /usr/bin/awk
{
if($1 ~ ".*>.*") print ","$2","$3
else if($2 ~ ".*>.*") print $1",,"$3
else if($3 ~ ".*>.*") print $1","$2","
else print
}
If in the your_file.txt you have:
Name>Ami
Admin>2
Oper>1
Name>Sum
Admin>3
Total>2
Name>Tar
Admin>1
Oper>2
With xargs -n3 you will get the output of the file every 3 lines (as one line):
Name>Ami Admin>2 Oper>1
Name>Sum Admin>3 Total>2
Name>Tar Admin>1 Oper>2
With awk '{gsub(/(Name|Admin|Oper)>/,""); print $1","$2","$3}' the values like Name> Admin> or Oper> will be replaced by an empty string and with print $1","$2","$3 the values (after >) will be printed with a comma.
If you use:
xargs -n3 < data3 | awk '{gsub(/(Name|Admin|Oper)>/,""); print $1","$2","$3}
you will get:
Ami,2,1
Sum,3,Total>2
Tar,1,2
Now, it will be removed unnecessary strings like Total>2. With the script.awk you can remove them but before we have to define the separator, in this case the comma (,).
The awk code like $1 ~ ".*>.*" will verify if the current string ($1, $2 or $3) does match with the pattern .*>.* if it does, then, the current string will not be printed.
Important: The script.awkworks by group. So, if there is a not valid column, this one must be placed instead of Name or Admin or Oper. For example if your_file.txt has:
Name>Ami
Total>2
Oper>1
Name>Sum
Admin>3
Total>2
Total>Tar
Admin>1
Oper>2
The output of the script will be:
Ami,,1
Sum,3,
,1,2
But if you have inside the your_file.txt:
Total>Ami
Total>2
Oper>1
Name>Sum
Admin>3
Total>2
Total>Tar
Admin>1
Total>2
the command will not work as you expect.
Note: If you want that your_file.txt be edited too, you will have to use tee your_file.txt at the end:
xargs -n3 < your_file.txt | awk '{gsub(/(Name|Admin|Oper)>/,""); print $1","$2","$3}' | awk -F',' --file script.awk | tee your_file.txt
Name>...record be missing at times or does it systematically appear at regular interval in the data to be processed ?