Issue with replace


 
Thread Tools Search this Thread
Top Forums Programming Issue with replace
# 1  
Old 07-03-2013
Issue with replace

Hi,
I have a problem with a replace of a pattern in a file.

Example of file:
CREATE TABLE TEST.TEST
(
ID_SOGGETTO BIGINT NOT NULL,
ENTE VARCHAR(64))
UNIQUE PRIMARY INDEX ( ID_SOGGETTO ,ENTE );

I want to replace the red pattern with another text:
i want to replace the text after the character ")" at the end of line up to the ";" character.
The file contain multiple CREATE TABLE statements.
I tryed with sed command..

Thanks
Marco
# 2  
Old 07-03-2013
Red pattern is missing in your post. Also can you add code tags.
# 3  
Old 07-03-2013
Sorry

CREATE TABLE TEST.TEST
(
ID_SOGGETTO BIGINT NOT NULL,
ENTE VARCHAR(64))
UNIQUE PRIMARY INDEX ( ID_SOGGETTO ,ENTE );
# 4  
Old 07-03-2013
Code:
sed 's#.*);#replace string#' file

# 5  
Old 07-03-2013
There may be multiple rows between the first line end with ")" and ";"

Code:
CREATE TABLE TEST.TEST 
(
ID_SOGGETTO BIGINT NOT NULL,
ENTE VARCHAR(64))
INDEX ( ENTE )
UNIQUE PRIMARY INDEX ( ID_SOGGETTO ,ENTE );

# 6  
Old 07-03-2013
Please use code tags as required by forum rules!

Your specification is very vague. Will the last line of your CREATE TABLE statement always be a one single index definition? And, there is nothing (= empty string) between ")" and ";" in your sample, unless you are talking of the previous line's ")", which cannot be considered in line based tools like awk or sed.

Applying a wild guess, I'd propose sth like
Code:
sed 's/^.*);/replacement;/' file

If that does not suit you, please be way more specific, providing a desired output sample.

EDIT: obviously we are NOT talking of single index definitions. And, I'd bet, the replacemant text will not be constant but vary from table definition to table definition...
# 7  
Old 07-03-2013
Code:
$
$ cat -n f84
     1  CREATE TABLE TEST.TEST1
     2  (
     3  ID_SOGGETTO BIGINT NOT NULL,
     4  ENTE VARCHAR(64))
     5  UNIQUE PRIMARY INDEX ( ID_SOGGETTO ,ENTE );
     6
     7  CREATE TABLE TEST.TEST2
     8  (
     9  ID_SOGGETTO BIGINT NOT NULL,
    10  ENTE VARCHAR(64))
    11  INDEX ( ENTE )
    12  UNIQUE PRIMARY INDEX ( ID_SOGGETTO ,ENTE );
    13
$
$
$ perl -lne 'BEGIN {undef $/; $rpl="REPLACEMENT_TEXT_HERE"} while(/(^CREATE.*?\(.*?\)$)(.*?\);)/msg){print "$1\n$rpl\n"}' f84
CREATE TABLE TEST.TEST1
(
ID_SOGGETTO BIGINT NOT NULL,
ENTE VARCHAR(64))
REPLACEMENT_TEXT_HERE
 
CREATE TABLE TEST.TEST2
(
ID_SOGGETTO BIGINT NOT NULL,
ENTE VARCHAR(64))
REPLACEMENT_TEXT_HERE
 
$
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

2. Shell Programming and Scripting

Issue with sed command does not replace exact string matched

I have a file change.sed more change.sed I fire the below command inorder to replace "190.169.11.15" with "10.4.112.240" in proxy.logsed -f change.sed proxy.log proxy.log has the below entry more proxy.log The command replaces both 190.169.11.15 & 190.169.11.155 as below: I am expecting... (17 Replies)
Discussion started by: mohtashims
17 Replies

3. Shell Programming and Scripting

to replace Date format issue

Hi, I have the below data in a file in one of the path, 101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31201207 1140689340000001 622113010547999999999003 000333333334RE ... (1 Reply)
Discussion started by: Ramyajiguru1
1 Replies

4. Shell Programming and Scripting

Perl newbie - regex replace all groups issue

Hello, Although I have found similar questions, I could not find advice that could help with my problem. The issue: I am trying to replace all occurrences of a regex, but I cannot make the regex groups work together. This is a simple input test file: The Vedanta Philosophy... (3 Replies)
Discussion started by: samask
3 Replies

5. Shell Programming and Scripting

find and replace issue using awk

Hi All, point 1. I have n number of environment variable files in different folders. All file names are ending with one thing common ie, *envset.sh point 2. All these contains Varilables and some other information like following *envset.sh ===>> ... (3 Replies)
Discussion started by: nitin.pathak
3 Replies

6. Shell Programming and Scripting

Find and replace issue

Hello Guys i am seeking help here is my issue I have several files i need to find "&" char and replcae with & or ' 1) It may be possible that in a file there are several occurance of &, & or ' but need to replace only & whihc does not have amp; and apos; 2)it may be the case out of... (7 Replies)
Discussion started by: lokaish23
7 Replies

7. Shell Programming and Scripting

replace issue with large files

I have the following problem: I have two files: S containing sentences (one in each row) and W containing files (one in each row). It might look like this: S: a b c apple d. e f orange g. h banana i j. W: orange banana apple My task is to replace in S all words that appear in W... (2 Replies)
Discussion started by: tootles564
2 Replies

8. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

9. Shell Programming and Scripting

Unix Arithmatic operation issue , datatype issue

Hi, I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding... (23 Replies)
Discussion started by: thambi
23 Replies

10. UNIX for Dummies Questions & Answers

Help search and replace issue!

I have no idea really what I am doing but I am very good at copy-paste code from smart people :) I found it a while back but can't get it now, I am looking for a simple command line prompt command to search and replace text in multiple files. I have a website with a ton of pages and all links... (6 Replies)
Discussion started by: scavok
6 Replies
Login or Register to Ask a Question