create txt file form data file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create txt file form data file
# 1  
Old 10-25-2012
MySQL create txt file form data file

File A.txt

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

Code:
LL07.txt
LL85.txt
LL37.txt

Eaach text file have below data as per file A

LL07.txt

Code:
Hello
prl
Fi Na=LL07_B_1 no 20
bye
q

LL85.txt

Code:
Hello                    
prl                      
Fi Na=LL85_A_1 no=40     
Fi Na=LL85_B_1 no=40  
Fi Na=LL85_C_1 no=30  
bye                      
q

LL85.txt

Code:
Hello                    
prl                      
Fi Na=LL37_A_1 no=60     
Fi Na=LL37_B_1 no=20  
Fi Na=LL37_C_1 no=50  
bye
q


Thanks a lot in advance
# 2  
Old 10-25-2012
Code:
for key in `awk ' { print $1 } ' A.txt | sort | uniq`
do
        echo "Hello\nprl" > ${key}.txt
        awk '/'$key'/ { print "Fi Na=" $2 " no=" $3 } ' A.txt >> ${key}.txt
        echo "bye\nq" >> ${key}.txt
done

Note: please use -e option for echo if you are using bash.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 10-25-2012
All in awk:

Code:
awk '{ $1 = $1 ".txt"  ;if (a[$1]) { a[$1] = a[$1] "\n"; };   a[$1] = a[$1] "Fi Na=" $2 " no=" $3;} END {  for (i in a) { print "Hello\nprl\n" a[i] "\nbye\nq" > i } }' A.txt

This User Gave Thanks to scottaazz For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Shell Programming and Scripting

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

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 (3 Replies)
Discussion started by: asavaliya
3 Replies

3. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

4. 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

5. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

6. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

7. 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

8. 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

9. UNIX for Dummies Questions & Answers

create file .txt

hi.i want to create a bash script called countfiles.sh, that will count the pack of files under the current file that their term satisfy a specific pattern. The script must show the total per file or on the whole. thank tou (4 Replies)
Discussion started by: battaglia
4 Replies

10. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies
Login or Register to Ask a Question