Shell script text file manipulation.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script text file manipulation.
# 1  
Old 07-20-2010
Shell script text file manipulation.

Hello,

I have mysql binary file which logs all the database queries and i to insert all queries log in to database. First i coverted binary file to text file. and start playing with it. Text file contains following queries, some samples are,
Code:
SET INSERT_ID=1;
INSERT INTO test (column1,column2,column3) VALUES ('column1value','
column2value ,'column3value')

SET INSERT_ID=2;
INSERT INTO test (column1,column2,column3) VALUES ('column1value','
column2value ,'column3value')

SET INSERT_ID=3;
INSERT INTO test1 (column1) VALUES ('column1value')

UPDATE test2 set column1 = Concat(chat, '
New User 49: bhjg '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee090-88f0'

UPDATE test2 set column1 = Concat(chat, '
New User 49: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee0-f0'

UPDATE test2 set column1 = Concat(chat, '
User Build27: this is good '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f072-00e0'

UPDATE test2 set column1 = Concat(chat, '
User Build27: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f06f-8f0'

UPDATE test2 set column1 = Concat(chat, '
New User 49: 2 '),seller_count = '0',buyer_count = '0',total_chat_lines = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '2311-rs'

SET INSERT_ID=4;
INSERT INTO test3 (
column1,
column2,
column3,

VALUES

(
column1value,
column2value,
column3value
)

1- I need terminator (;) at end of every query. Same as follows,
2- I need to append insert_id before any INSERT INTO query before column1 and it's value in VALUES section before column1value.

Same as follows. Can someone please help me how to get this. I tried sed/awk but no success yet.
Code:
SET INSERT_ID=1;
INSERT INTO test (insert_id,column1) VALUES (1,'column1value');

SET INSERT_ID=2;
INSERT INTO test (insert_id,column1,column2,column3) VALUES (2,'column1value','
column2value ,'column3value');

SET INSERT_ID=3;
INSERT INTO test1 (insert_id,column1,column2,column3) VALUES (3,'column1value','
column2value ,'column3value');

UPDATE test set chat = Concat(chat, '
New User 49: bhjg '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee090-88f0';

UPDATE test set chat = Concat(chat, '
New User 49: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee0-f0';

UPDATE test set chat = Concat(chat, '
User Build27: this is good '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f072-00e0';

UPDATE test set chat = Concat(chat, '
User Build27: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f06f-8f0';

UPDATE test set chat = Concat(chat, '
New User 49: 2 '),seller_count = '0',buyer_count = '0',total_chat_lines = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '2311-rs';

SET INSERT_ID=4;
INSERT INTO test3 (
insert_id,
column1,
column2,
column3,

VALUES

(
4,
column1value,
column2value,
column3value
);

Thanks in advance.

Last edited by Franklin52; 07-20-2010 at 01:12 PM.. Reason: Correcting code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text manipulation with sed/awk in a bash script

Guys, I have a variable in a script that I want to transform to into something else Im hoping you guys can help. It doesn't have to use sed/awk but I figured these would be the simplest. DATE=20160120 I'd like to transform $DATE into "01-20-16" and move it into a new variable called... (8 Replies)
Discussion started by: dendenyc
8 Replies

2. UNIX for Dummies Questions & Answers

Text File Manipulation

Hello, Supposing I had a huge list as follows: TAC manufacturer Device Type 1392600 LG D959 LG-D959TS FeaturePhone 1409700 LG V410 FeaturePhone 35150806 LG F350S FeaturePhone 35165206 Samsung GT-E1200 FeaturePhone 35194505 Nokia Asha 200 FeaturePhone but I want to make it look like... (3 Replies)
Discussion started by: Cludgie
3 Replies

3. Shell Programming and Scripting

Text file manipulation

Hi Gurus, I have a question I have a flat file like below with three fields (3 rd field is amt) ad|B|500 cc||100 dd|C|600 ee||900 Need to write a code in such a way that when second field is empty then do sum of third field So in this case it will be 100 +900 I tried but no luck... (1 Reply)
Discussion started by: patricjemmy6
1 Replies

4. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

5. UNIX for Dummies Questions & Answers

Text File Manipulation Help

Hi I've two text files FILE_1 and FILE_2 as shown below: FILE_1.txt CO Contig1 342 12 11 U GGGCTGACGTGGCCGCTAATACGACTCACTATAGGG*AGAGAAGTCATTTTCTTGTTTAG BQ 35 35 35 50 50 50 50 50 50 50 50 60 65 65 65 65 65 65 65 65 65 65 65 65 50 AF GP5UOVN01AOPE0 U 1 AF GP5UOVN01AT8W3 U 1 ... (1 Reply)
Discussion started by: Fahmida
1 Replies

6. Shell Programming and Scripting

Text File Manipulation

Hi, I need to write shell script for the scenario explained below - datafile.txt AcctNum,code,Region,,,, 12345451,AN ,abaab 12345452,AN ,xccxc 76677545,RP ,acxcc 43567878,RP ,afghh 32190900,AN ,afrfrf 87312345,AN ,aqaw I have a text file (datafile.txt)... (1 Reply)
Discussion started by: ravigupta2u
1 Replies

7. Shell Programming and Scripting

File text manipulation

What I am trying to do is make a script that will add a port number within a section of a file if it already doesn't exist in that section of the file. The particular line that I would like to add the port number to in the file is formatted like this: TCPPORTS="25 80 125 443 8080 10000" For... (3 Replies)
Discussion started by: nullifx
3 Replies

8. UNIX for Dummies Questions & Answers

Text file manipulation

I am a new unix user & I wanted to work with unix as it is very good in text manipulations. I need a little help. I will be grateful if someone can help me out. I need help in grepping a pattern of numbers from one file to another file. Specific details are as follows: File one contains only... (4 Replies)
Discussion started by: Ezy
4 Replies

9. UNIX for Dummies Questions & Answers

Text file manipulation

Hi, I need to remove lines from a text file that are less than certain length in UNIX. For example, test.txt file contains the following lines: abcdefghijklmnopqrstuvwxyz. 123456789009876543211234567 This line to be removed. zyxwvutsrqponmlkjihgfedcba. The length of each line is supposed... (5 Replies)
Discussion started by: svannala
5 Replies

10. Shell Programming and Scripting

shell script : text manipulation (easy quesiton)

hi, i am newbie in shell script i want to do the following: given a filename like abc.txt i want to change the name to abc.properties how to do it? pls enligthen me. thanks (3 Replies)
Discussion started by: champion
3 Replies
Login or Register to Ask a Question