create txt file form data file and add some line on it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create txt file form data file and add some line on it
# 1  
Old 10-14-2012
MySQL create txt file form data file and add some line on it

Hi Guys,

I have file A.txt

Code:
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

Code:
AK1521.txt

Code:
Hi
Welocme 
File Name =AK1521_4A_1 no=10
File Name =AK1521_4B_1 no=10
File Name =AK1521_4C_1 no=10
Bye

Code:
AK2536.txt

Code:
Hi
Welocme 
File Name =AK2536_4A_1 no=10
File Name =AK2536_4B_1 no=10
File Name =AK2536_4C_1 no=10
Bye

Code:
AK3164.txt

Code:
Hi
Welocme 
File Name =AK3164_4A_1 no=10
File Name =AK3146_4B_1 no=10
File Name =AK3146_4C_1 no=10
Bye

# 2  
Old 10-14-2012
Code:
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[i]" no=10" > s}
print "Bye" > s}' file

If you want to create in another directory. Use

Code:
s="/home/kka/out/"$0".txt";


Last edited by pamu; 10-14-2012 at 03:09 AM..
This User Gave Thanks to pamu For This Post:
# 3  
Old 10-14-2012
MySQL

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
# 4  
Old 10-14-2012
Quote:
Originally Posted by asavaliya
If i wand add some more line in loop ....

File Name =AK1521_4A_1 no=20
File Name =AK1521_4B_1 no=20
File Name =AK1521_4C_1 no=20
This line is yours..Smilie

Code:
for(i=1;i<=3;i++){print "File Name ="$0""a[i]" no=10" > s}

Do what you want to do....Smilie

3 is count repetitive operations.
If you want add three more lines like above.

Code:
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[i]" no=10" > s}
for(i=1;i<=3;i++){print "File Name ="$0""a[i]" no=20" > s}
print "Bye" > s}' file

It will add total 6 lines.Smilie
Hope this helps you..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. UNIX for Beginners Questions & Answers

How can i add each line from a txt file to different files in the same directory?

Hello, this is my first thread here :) So i have a text file that contains words in each line like abcd efgh ijkl mnop and i have 4 txt files, i want to add each line to each file, like file 1 gets abcd at the end; file 2 gets efgh at the end .... I tried with: cat test | while read -r... (6 Replies)
Discussion started by: azaiiez
6 Replies

3. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

4. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. Shell Programming and Scripting

Copy data form File A and Create File B

File A I have list of : ABCND1 ABCND2 ABCnd3 ABCnd4 I want file B like below Start+ S Pate=ABCND1 AAlo1 S Pate=ABCND1 Q1234 S Pate=ABCND1,P12345 (7 Replies)
Discussion started by: asavaliya
7 Replies

8. Shell Programming and Scripting

Select some lines from a txt file and create a new file with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
Discussion started by: capnino
4 Replies

9. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies
Login or Register to Ask a Question