Help needed to remove a char from a specified sub-string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed to remove a char from a specified sub-string
# 1  
Old 09-21-2010
Help needed to remove a char from a specified sub-string

Hi!

I'm having trouble usind sed to remove the char ' from within a database's varchar register's sql.
For example, on the following sql:
Code:
INSERT INTO patrimonio_municipal.patrimonio_municipal_airc_tmp 
Values('|Estação Elevatória|',|16723|,'|Grandes Reparações|',
     '|2010-03-26 00:00|',|13|,'|99|','|Outras infra-estruturas|',
    '|Imóveis urbanos, com finalidade operativa|','||','|Etar's e Estações Elevatórias|',
    '|Outras Infra-Estruturas|');

i want to remove the char ' (single quote) from within '|Etar's e Estações Elevatórias|'.
One sed regex to resolve this is:
Code:
 sed -e "s/'|\(.*\)'s\(.*\)|'/'|\1\2|'/g"

But it only functions if the character next to ' is s.
The idea is to remove the char ' (it would be even better to remove its multiple occurrences) from within the sequences '| and |'

Every help is very appreciated.

Thanks a lot in advance,
David Pinheiro

Last edited by jim mcnamara; 09-21-2010 at 02:38 PM.. Reason: code tags please; chop width
# 2  
Old 09-21-2010
Try this then:

Code:
sed -e "s/\([^|]\)'\([^|]\)/\1\2/g"

# 3  
Old 09-21-2010
Code:
 $ ruby -pne 'gsub(/([^|])\047([^|])/,"\\1\\2")' file


Last edited by kurumi; 09-21-2010 at 09:58 PM..
# 4  
Old 09-23-2010
Thanks a lot for your help.
It worked fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to remove a char before a pattern?

Hi I have a file where i want to remove a char before a specific pattern. exp: CREATE TABLE ( A, B, C, ----comma needs to be removed )AS SELECT A, B, C, ----comma needs to be removed FROM TABLE. So i want to delete the comma(,) after the C both ways.Pattern can be... (11 Replies)
Discussion started by: raju2016
11 Replies

2. Shell Programming and Scripting

Remove double char occurences

I have a file with random characters where every time a char occurs twice, one occurrence must be removed. Eg. asjkdhaSSd Must become: asjkdhaSd Anybody has a SED script in mind to do it? (1 Reply)
Discussion started by: rlopes
1 Replies

3. UNIX for Dummies Questions & Answers

Remove char if not a number

I need to write a BASH script that takes a 2 character string and removes the second character if it is not a digit e.g. If the string is numberical value >9 e.g. string1 = '34' then leave string1 = '34'. However if the string is <10 e.g. string1 = '3X' then remove the second char (which... (7 Replies)
Discussion started by: millsy5
7 Replies

4. Shell Programming and Scripting

How to remove the # char form a line?

Hi, my file has below details and I want remove the # char from only specific line. #TEST:00:START #TEST1:01:INPROCESS #TEST2:02:ABOUTTO #TEST3:03:COMP i.e if want remove the # from 2nd line then file to be updated as #TEST:00:START TEST1:01:INPROCESS #TEST2:02:ABOUTTO... (6 Replies)
Discussion started by: sandyrajh
6 Replies

5. Red Hat

How to remove a special char using sed

consider this is my sample file format. in this i want to remove ^@ with space . please help me in this problm 7305,1310184890,0,0,12,201370,FCASTBHBR0 ,XX ,2,1,2,0,^@,1,1,0,3,1303862400,0,1577923199,1,10,FCASTOR SEED EX-BHABHAR ... (2 Replies)
Discussion started by: ponmuthu-lnx
2 Replies

6. Shell Programming and Scripting

Replace char between chars - help needed

Hello, I have a csv file with "^" as text delimiters and "|" as field delimiters. It's converted from a xls file. One record looks like this: ^Tablete Internet^|Archos|501838|^Tableta Internet ARCHOS 80 G9 ...| ... (more lines) ... "501|838"^|330.00|USD|sl|12|0|Link|^router wireless 150... (10 Replies)
Discussion started by: go0ogl3
10 Replies

7. UNIX Desktop Questions & Answers

Help me to remove junk char

I wanted to remove junk char in my csv. :mad: Input file format: "17","9986782190","0","D","2" "17","9900918331","0","D","2" "13","9986782194","0","A","2" Output file format 9986782190 9900918331 9986782194 And one more thing all the time "13"," this will be different Ex: . (2 Replies)
Discussion started by: Siddartha
2 Replies

8. Shell Programming and Scripting

Remove char after Colon

Hi guys, This is my input 2735:<7001> 34 789 701 2 2774:<7001> 34 789 701 2 How to delete characters after colon : Including colon : too ? My output should... (3 Replies)
Discussion started by: gowrishankar05
3 Replies

9. Shell Programming and Scripting

can I remove the first char using AWK?

Hi everyone, suppose that I have the following line: #test your knowledge can I use AWK to print the word "test" only? without the #? what should I change to this: awk '{print $1}' thanks in advance guys (2 Replies)
Discussion started by: Abdulelah
2 Replies

10. Shell Programming and Scripting

How to remove new line char from a string

Hi Can anyone tell me how can i remove new line character from a string. My requirement is to read a line from a file and store it to a string. read line string1=$line read line string2=$line echo $string1$string2 The result i am getting in different line. i want the output in the same... (1 Reply)
Discussion started by: sreedivia
1 Replies
Login or Register to Ask a Question