Skip to main content
added 288 characters in body
Source Link
Marius_Couet
  • 1.2k
  • 5
  • 14

You can use awk using a script like that (tst.awk):

BEGIN{print "#reference_group_id serials_from_ref_group group_id serials_from_group"}
$1 ~ /^reference_/ {ref=$1;ser=$2;next}
{
        for(i=1;i<=length($2);i++){
                print ref, substr(ser,i,1), $1, substr($2,i,1)
        }
}

I supposed that your reference_group_id is always begining with reference_ to store it to a var called ref, and store the serials_from_ref_group to ser. We then use both these var in a loop.

Then a line like that should work :

awk -f tst.awk file

As your output is formatted by column you can pipe the output to column -t

awk -f tst.awk file | column -t

Explanation for awk script :

  • BEGIN is executed once only, before the first input record
  • $1 ~ /^reference_/ if $1 matches the regular expression ^reference_
  • length($2) length of the second field
  • substr(ser,i,1) substring of ser starting at the i position and length of 1

You can use awk using a script like that (tst.awk):

BEGIN{print "#reference_group_id serials_from_ref_group group_id serials_from_group"}
$1 ~ /^reference_/ {ref=$1;ser=$2;next}
{
        for(i=1;i<=length($2);i++){
                print ref, substr(ser,i,1), $1, substr($2,i,1)
        }
}

I supposed that your reference_group_id is always begining with reference_ to store it to a var called ref, and store the serials_from_ref_group to ser. We then use both these var in a loop.

Then a line like that should work :

awk -f tst.awk file

As your output is formatted by column you can pipe the output to column -t

awk -f tst.awk file | column -t

You can use awk using a script like that (tst.awk):

BEGIN{print "#reference_group_id serials_from_ref_group group_id serials_from_group"}
$1 ~ /^reference_/ {ref=$1;ser=$2;next}
{
        for(i=1;i<=length($2);i++){
                print ref, substr(ser,i,1), $1, substr($2,i,1)
        }
}

I supposed that your reference_group_id is always begining with reference_ to store it to a var called ref, and store the serials_from_ref_group to ser. We then use both these var in a loop.

Then a line like that should work :

awk -f tst.awk file

As your output is formatted by column you can pipe the output to column -t

awk -f tst.awk file | column -t

Explanation for awk script :

  • BEGIN is executed once only, before the first input record
  • $1 ~ /^reference_/ if $1 matches the regular expression ^reference_
  • length($2) length of the second field
  • substr(ser,i,1) substring of ser starting at the i position and length of 1
Source Link
Marius_Couet
  • 1.2k
  • 5
  • 14

You can use awk using a script like that (tst.awk):

BEGIN{print "#reference_group_id serials_from_ref_group group_id serials_from_group"}
$1 ~ /^reference_/ {ref=$1;ser=$2;next}
{
        for(i=1;i<=length($2);i++){
                print ref, substr(ser,i,1), $1, substr($2,i,1)
        }
}

I supposed that your reference_group_id is always begining with reference_ to store it to a var called ref, and store the serials_from_ref_group to ser. We then use both these var in a loop.

Then a line like that should work :

awk -f tst.awk file

As your output is formatted by column you can pipe the output to column -t

awk -f tst.awk file | column -t