String manipulation with a script.
Hello,
I'm a newbie in linux and I have a question about linux script and string manipulation. In my case I have file with a dump of a mysql database. ex: INSERT INTO test_table VALUES ('first','1','','','test'); I would like to change this line to add a new parameter. For example, if I need to add the parameter 'A' in fourth position I will have to count the number of comma (3) and insert the letter 'A'. My question is. Is it possible to do this with a simple script. If yes, what can I use as command to count a special charater and insert a small string after x special charaters? Thanks in advance. |
"what can I use as command to count a special charater and insert a small string after x special charaters?"
You can probably do this with the sed command. See: man sed ___________________________________ Be prepared. Create a LifeBoat CD. http://users.rcn.com/srstites/LifeBo...home.page.html Steve Stites |
I would probably use an update statement:
Code:
#!/bin/sh Otherwise you will have to parse out the data for each column and build you insert statement. Since you don't mess with the existing data with the update script you are less likely to corrupt it. |
What exectly are you trying to do?
change a MySQL dump file? do you want a general solution or a one off? if it's a one-off, just use sed. billy |
save the following code as mod_tok.c and compile with make mod_tok.
Code:
#include <stdio.h> To run ./mod_tok 3 \\'A\\' , < example.sql > newfile.sql To change 'first', ./mod_tok 1 second \\' < example.sql > newfile.sql I'm sure there are sql commands to do what you need as well. naflan |
All times are GMT -5. The time now is 12:17 AM. |