script to arrange file in specific format

Hi All,

I am new to forum, I am looking to arrange a file in specific format but unable to get the formula to do it, already googled for the same, but didnt find the answer :(. hope to get help here :o:o:o:o:o

I have to files :

$ cat Dev_List2
0685
0686
0687
0688
0689
068A
068B
068C
068D
068E
068F
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
069A
$ cat Dev_Meta_Member
2
4
8
4
2
2

I want to arrange this file in specific format i.e
Template :

form meta from dev XXXX, config=STRIPED;
add dev XXXX to meta XXXX;

i.e

form meta from dev 0685, config=STRIPED;
add dev 0686 to meta 0685;
form meta from dev 0687, config=STRIPED;
add dev 0688 to meta 0687;
add dev 0689 to meta 0687;
add dev 068A to meta 0687;
form meta from dev 068B, config=STRIPED;
 add dev 068C to meta 068B;
  add dev 068D to meta 068B;
  add dev 068E to meta 068B;
  add dev 068F to meta 068B;
  add dev 0690 to meta 068B;
 add dev 0691 to meta 068B;
 add dev 0692 to meta 068B;
form meta from dev 0693, config=STRIPED;
 add dev 0694 to meta 0693;
 add dev 0695 to meta 0693;
 add dev 0696  to meta 0693;
form meta from dev 0697, config=STRIPED;
 add dev 0698 to meta 0697;
form meta from dev 0699, config=STRIPED;
 add dev 069A to meta 0699;

Please revert, if you need more details on this.

awk '{
for(i=1;i<=$0;i++)
{
 getline rec < "Dev_List2"
 if(i==1)
 {
  first=rec
  print "form meta from dev " rec ", config=STRIPED;"
  continue
 }
 print "add dev " rec " to meta " first ";"
}
}' Dev_Meta_Member
1 Like

I was looking for this from past two weeks & cant google it & it took just 5 min to get the code here.

thanks aton elixir_sinari .

i will now make the rest of the script.

This piece of code has reduce my work from 2 hours to 10 min or less.:):):):):):slight_smile: