The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Best way to remove sections of text from a file cals64 Shell Programming and Scripting 8 09-22-2008 01:16 PM
Search a string and append text after the string kesu2k Shell Programming and Scripting 8 07-18-2008 08:35 PM
remove specified text from file raidzero Shell Programming and Scripting 2 06-19-2008 10:10 AM
Remove duplicate text dejavu88 Shell Programming and Scripting 7 06-08-2008 05:37 PM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 09:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-06-2008
shantanuo shantanuo is offline
Registered User
  
 

Join Date: Aug 2008
Location: Mumbai
Posts: 79
remove text from string

I use the following command to know the create table structure.

mysqldump myDBName myTBName -d --compact

And I get the following output...

CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154 DEFAULT CHARSET=latin1 COMMENT='Forum threads';

I want to remove everything after AUTO_INCREMENT till the end of that line. But I want to retain the last semicolon ;
The engine can be MyISAM or InnoDB or Memory and so on. something like...

mysqldump myDBName myTBName -d --compact | grep --keep engine --remove others
  #2 (permalink)  
Old 11-06-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Something like this?

Code:
root@isau02:/data/tmp/testfeld> cat infile
CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154 DEFAULT CHARSET=latin1 COMMENT='Forum threads';
root@isau02:/data/tmp/testfeld> sed 's/\(^.*AUTO_INCREMENT[^ ]*\) .*/\1;/g' infile
CREATE TABLE `tblThreads` (
`threadID` smallint(4) unsigned zerofill NOT NULL auto_increment,
`threadTitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`threadID`)
) ENGINE=MyISAM AUTO_INCREMENT=154;
  #3 (permalink)  
Old 11-06-2008
shantanuo shantanuo is offline
Registered User
  
 

Join Date: Aug 2008
Location: Mumbai
Posts: 79
I do not want auto_increment as well, but do want engine...
ENGINE=MyISAM ;
  #4 (permalink)  
Old 11-06-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
sed 's/\(.*ENGINE=MyISAM[^ ]*\) .*/\1;/g' infile
  #5 (permalink)  
Old 11-06-2008
shantanuo shantanuo is offline
Registered User
  
 

Join Date: Aug 2008
Location: Mumbai
Posts: 79
Thanks.
Only 2 points to note...
1) The engine can be something else like InnoDB and not necessarily MyISAM
2) Though it was not mentioned in the original question, is it possible to keep auto_increment but reset it to 0?
ENGINE=SomeThingChanging AUTO_INCREMENT=0;
  #6 (permalink)  
Old 11-06-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
sed 's/\(.*ENGINE.*AUTO_INCREMENT=\).*/\10;/g' infile
  #7 (permalink)  
Old 11-07-2008
shantanuo shantanuo is offline
Registered User
  
 

Join Date: Aug 2008
Location: Mumbai
Posts: 79
Perfect and amazing.
(I guess, mysqldump does not have any built-in tool to do this)
Closed Thread

Bookmarks

Tags
grep, replace, truncate

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0