Character replacement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Character replacement
# 1  
Old 09-03-2007
Character replacement

Hi,

I am working on a command that replaces some occurrences of quotation marks in file. The quotation mark cannot be the first or the last character in line and cannot be preceded or followed by a comma.

I am not an expert in regular expressions, but I managed to create the following command.

sed 's/\([^,]\)\"\([^,]\)/\1\"\"\2/g' file.txt

Can you please verify it or tell me how to do it better? Any help will be appreciated.

Regards,
Pit
# 2  
Old 09-04-2007
Hi,

Small update regarding my problem. Currently I need to match pattern from the last occurence of
Code:
","

or
Code:
,,"

till the end of line. For example matching on the following line:

Code:
"one","two","three",,"five",,"sev"e,n"

should return
Code:
sev"e,n

. I would like to use sed or awk, but any other solution will be fine. Can you please help me writing a proper regular expression?

Pit
# 3  
Old 09-06-2007
you could do within vi the global repleace

:g/c2/s//c5/g

this replaces everything with c2 to c5. you could some how work this into a script to do a larger directory if you do not feel like vi a file. not sure though
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Special character replacement

Hi Guys, I have a file which needs to be replaced with tab delimited AA§Orgin Name§Mapping based on prod_usa§§§§ BB§Date§2019-08-11 23:30:01§§§§ I am trying below code sed 's// /g' test.txt Expected AA|Orgin Name|Mapping based on prod_usa||| BB|Date|2019-08-11 23:30:01|||| (6 Replies)
Discussion started by: rohit_shinez
6 Replies

2. Shell Programming and Scripting

Trigger email from script if the Special Character replacement is successfull

Hello Gurus, I have a script developed... #!/bin/bash #--------------------------------------------------------------------- # This pScript will remove/replace the special characters fromfiles #--------------------------------------------------------------------- trxdate="`date... (1 Reply)
Discussion started by: nanduedi
1 Replies

3. Shell Programming and Scripting

sed - replacement file path with variable - Escaping / character

Hi,, I have the line below in a file: $!VarSet |LFDSFN1| = '"E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1I want to write a script to change... (2 Replies)
Discussion started by: carlr
2 Replies

4. UNIX for Dummies Questions & Answers

global search and replacement of a non-ascii character

Hi, I need to do a global search and replacement of a non-ascii character. Let me first give the background of my problem. Very frequently, I need to copy set of references from different sources. Typically, a reference would like this: Banumathy et al., 2002 G. Banumathy, V. Singh and U.... (1 Reply)
Discussion started by: effjay
1 Replies

5. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

6. Programming

python, character replacement

Hello, I need to do this in python but I'm just learning py and it's quite urgent. I have a script I created and need an interactive python script to modify part of a line. MY SCRIPT #ligand prep. Uses 'ind' prefix. The initial ligand must be ind.pdb. This #generates ind.pdbqt.... (0 Replies)
Discussion started by: gav2251
0 Replies

7. UNIX for Dummies Questions & Answers

banner character replacement

Can we able to replace the character # in banner command with some other characters. Can we able to blink the character in Kornshell (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

8. Shell Programming and Scripting

Sed-Special character replacement

Hi I want to replace ./testsed.ksh with testsed.ksh ./ is to be removed scriptnm=`sed -e 's/\.///' $0 does not work Please help (3 Replies)
Discussion started by: usshell
3 Replies

9. Shell Programming and Scripting

KSH - Character Replacement

Hey all. Easy question. I have a (ksh) varaible x. It contains the following (for example): N557788 I want to replace the "N" with a "-". I've done this before but for the life of me I cannot remember how I did it. Thanks. mtw (2 Replies)
Discussion started by: mixxamike
2 Replies

10. Shell Programming and Scripting

Help needed in character replacement in Korn Shell

How do I replace a space " " character at a particular position in a line? e.g. I have a file below $ cat i2 111 002 A a 33 0011 B c 2222 003 C a I want all the 1st spaces to be replaced with forward slash "/" and the 3rd spaces to have 5 spaces to get the output below: 111/002... (8 Replies)
Discussion started by: stevefox
8 Replies
Login or Register to Ask a Question