Sed-Special character replacement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed-Special character replacement
# 1  
Old 05-22-2008
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
# 2  
Old 05-22-2008
Quote:
Originally Posted by usshell
Hi

I want to replace ./testsed.ksh
with
testsed.ksh

./ is to be removed

scriptnm=`sed -e 's/\.///' $0

does not work

Please help
sed -e 's/\.\///g' $0
# 3  
Old 05-22-2008
Hi

using sed

echo './testsed.ksh' | sed 's#\./##'

using awk

echo './testsed.ksh' | awk -F"/" '{print $NF}'

one more

basename ./testsed.ksh

Thanks
Penchal
# 4  
Old 05-22-2008
Code:
$ echo $var
./testsed.ksh
$ echo $var | sed 's:^\./::'
testsed.ksh
$

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

sed add special character

Hi all I got test.test.test and need test.test\.test * I need the backslash before the last dot in the line I tried echo test.test.test | sed 's/\./\\./g' but it gives me test\.test\.test Thanks (7 Replies)
Discussion started by: stinkefisch
7 Replies

3. UNIX for Dummies Questions & Answers

Replacing special character with sed

Hi All, I have a text file that contains I1SP2 *=*=Y=M=D001D My requirement is to replace all occurrence of =* to =Z expected o/p is I1SP2 *=Z=Y=M=D001D I have tried with sed 's/=*/=Z/g' file sed 's!\=*!\=Z/g' file sed 's!\=*!\=Z!g' file sed 's!\=\*!\=Z!g' file but its not... (3 Replies)
Discussion started by: gotamp
3 Replies

4. 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

5. 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

6. Shell Programming and Scripting

How to replace special character using sed?

How can I replace the follong text including to number 7000? cat tmp0.txt Winston (UK) Wong I would the 7000 to replace Winston (UK) Wong. I fail with method below: sed ' s /Winston\(UK\)Wong/7000 tmp0.txt' (1 Reply)
Discussion started by: vivien_chu
1 Replies

7. Shell Programming and Scripting

how to replace the special character with another using SED

I have the replace the pattern in the file , ); to ); Could someone please help me to get this command. (2 Replies)
Discussion started by: mohan.bit
2 Replies

8. Shell Programming and Scripting

sed special character replace

I need to do the following: text in the format of: ADDRESS=abcd123:1111 - abcd123:1111 is different on every system. replace with: ADDRESS=localhost:2222 sed 's/ADDRESS=<What do I use here?>/ADDRESS=localhost:2222/g' Everything I've tried ends up with: ... (3 Replies)
Discussion started by: toor13
3 Replies

9. Shell Programming and Scripting

Decode %s Special Character in Sed

Greetings, I am doing something that I don't know if it is possible... I have a file with a line looks like this: <%s \n%s / %s \n%s \n> and I am trying to replace this line with <%s \n%s \n%s / %s \n%s \n> in Shell script with sed command... StringToReplace='%s \n%s / %s \n%s \n'... (2 Replies)
Discussion started by: wasabihowdi
2 Replies

10. Shell Programming and Scripting

sed and special character in data

I have a script that is reading an existing report, pulling out the customer code, then tacking on the customer name from another file and replacing the existing customer code with the new field. This was written for me by someone else. I'm not real familiar with sed. The data is getting into... (3 Replies)
Discussion started by: MizzGail
3 Replies
Login or Register to Ask a Question