Hi Guys,
I have file A.txt
File A Data
AK1521
AK2536
AK3164
I want create text file of all data above and write some data on each file.
want Output on below folder
/home/kka/out
AK1521.txt
Hi
Welocme
File Name =AK1521_4A_1 no=10
File Name =AK1521_4B_1 no=10
File Name =AK1521_4C_1 no=10
Bye
AK2536.txt
Hi
Welocme
File Name =AK2536_4A_1 no=10
File Name =AK2536_4B_1 no=10
File Name =AK2536_4C_1 no=10
Bye
AK3164.txt
Hi
Welocme
File Name =AK3164_4A_1 no=10
File Name =AK3146_4B_1 no=10
File Name =AK3146_4C_1 no=10
Bye
pamu
2
awk 'BEGIN{split("_4A_1,_4B_1,_4C_1",a,",")}{s=$0".txt";print "Hi\nWelocme" > s;
for(i=1;i<=3;i++){print "File Name ="$0""a" no=10" > s}
print "Bye" > s}' file
If you want to create in another directory. Use
s="/home/kka/out/"$0".txt";
1 Like
Perfect Buddy !!
If i wand add some more line in loop ....
like
File Name =AK1521_4A_1 no=20
File Name =AK1521_4B_1 no=20
File Name =AK1521_4C_1 no=20
pamu
4
This line is yours..
for(i=1;i<=3;i++){print "File Name ="$0""a" no=10" > s}
Do what you want to do....
3 is count repetitive operations.
If you want add three more lines like above.
awk 'BEGIN{split("_4A_1,_4B_1,_4C_1",a,",")}{s=$0".txt";print "Hi\nWelocme" > s;
for(i=1;i<=3;i++){print "File Name ="$0""a" no=10" > s}
for(i=1;i<=3;i++){print "File Name ="$0""a" no=20" > s}
print "Bye" > s}' file
It will add total 6 lines.
Hope this helps you..