![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| input text into file | cannonfodder | Shell Programming and Scripting | 1 | 12-15-2007 10:37 AM |
| regex to delete multiple blank lines in a file? | fedora | Shell Programming and Scripting | 6 | 10-11-2007 05:36 PM |
| Apply Regex to input read | bonekrusher | UNIX for Dummies Questions & Answers | 3 | 09-23-2007 03:45 PM |
| sed, grep, awk, regex -- extracting a matched substring from a file/string | ropers | Shell Programming and Scripting | 2 | 05-23-2006 02:56 PM |
| how to get input from file | ajaya | Shell Programming and Scripting | 1 | 04-05-2006 03:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Here's the problem... I have a mysqldump file and I need to put single quotes around the date/time timestamp. So for example I have a line like: Code:
INSERT INTO attachments VALUES (1,182,2004-08-06 09:24:04,'description'... and I need it to become Code:
INSERT INTO attachments VALUES (1,182,'2004-08-06 09:24:04','description'... I tried Code:
cat backup.sql | sed s/\,200/,\'200/ | sed s/..:..:../\&\'/ | less and it did what I wanted, however it would also add a single quote infront of the first occurance of 200 so eventually it would insert Code:
('2005,20041,2003-05-06 10:13:12',...
So then I attempted Code:
cat backup.sql | sed s/.*\,.*\,/\&\'/ | sed s/..:..:../\&\'/ | less but it seems to only add the single quote after the time. I can't figure out how to get the single quote before the date as well. Anyone able to provide assistance? Thanks! Primal |
|
||||
|
@unilover When I run your command it returns: Code:
\1 not defined in the RE @Franklin52 When I run your command it places the single quotes around the dates but it removed the commas Code:
...VALUES (1 182 '2004-... I was able to get it with this Code:
sed s/VALUES\ \([0-9]*\,[0-9]*\,/\&\'/ | sed s/..:..:../\&\'/ but then I realized that the timestamp also appears in other tables (different fields and more than once) This is where I am right now Code:
sed s/....-..-..\ ..:..:../\'&\'/g The only problem with that is some timestamps already have single quotes around them and now after this line, some timestamps get 2 singles quotes surrounding them ''2004-08-06 09:24:04'' Is there anyway to do it so that it skips any timestamps that already have quotes? I can do Code:
s/,....-..-..\ ..:..:../\'&\'/g but that would place the single quote ',2004-08-06 09:24:04' Is it possible to include the comma in the search and then place the single quote right after it? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|