using sed or gsub to substitute characters!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using sed or gsub to substitute characters!
# 1  
Old 10-31-2010
using sed or gsub to substitute characters!

Is there a way to substitute the URL-encoding references of ( & and ` ) with their actual appearance? for example....
%26 is &
say I want to convert every %26 in my file to &.....


Code:
awk '{gsub(/%26/,"&");print}'



Is there a way to do this?

I also want to be able to convert ` too!

Last edited by puttster; 10-31-2010 at 02:45 AM..
# 2  
Old 10-31-2010
& is the pattern space. \& is the character "&". \ is called "escape" it means take the next character literally not as a special character or a metacharacter.

Code:
sed /%26/\&/g'

is what it seems you are looking for
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 10-31-2010
Quote:
Originally Posted by jim mcnamara
& is the pattern space. \& is the character "&". \ is called "escape" it means take the next character literally not as a special character or a metacharacter.

Code:
sed /%26/\&/g'

is what it seems you are looking for
Oh, yeah that makes a whole lot of sense.. thank you!
# 4  
Old 10-31-2010
Quote:
Originally Posted by puttster

Code:
awk '{gsub(/%26/,"&");print}'

Code:
awk '{gsub(/%26/,"\\&");print}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Substitute a character with sed

hi all, i'd like to modify a file with sed , i want to substuite a char "-" with "/" how can i do this? Thanks for all regards Francesco (16 Replies)
Discussion started by: Francesco_IT
16 Replies

2. Shell Programming and Scripting

Replace characters in string with awk gsub

Hi I have a source file that looks like a,b,c,d,e,f,g,h,t,DISTI(USD),MSRP(USD),DIST(EUR),MSRP(EUR),EMEA-DISTI(USD),EMEA-MSRP(USD),GLOBAl-DISTI(USD),GLOBAL-MSRP(USD),DISTI(GBP), MSRP(GBP) I want to basically change MSRP(USD) to MSRP,USD and DIST(EUR) to DIST,EUR and likewise for all i'm using... (3 Replies)
Discussion started by: r_t_1601
3 Replies

3. Shell Programming and Scripting

Substitute special Characters into a file

Hi experts :) I need to replace special characters into a file , in the followiing way : " --> "" ' --> '' _--> \_ I tried with the sed command but I'm getting and error ksh: $: not found. ksh: $: not found. sed: Function s/\/\/ cannot be parsed. Any idea ? Thanks , KOLAS... (2 Replies)
Discussion started by: Kolas79
2 Replies

4. Shell Programming and Scripting

sed substitute command -- need help

I am trying to do what I thought should be a simple substitution, but I can't get it to work. File: Desire output: I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

gsub in Awk to capture count of replaced characters

Hi , I am working on a script to replace special characters in ASCII file with '?'. We need to get count of replaced characters from file. I am new to Awk and i read, # The gsub function returns the number of substitutions made. I was trying to replace characters with below... (10 Replies)
Discussion started by: Akshay
10 Replies

6. UNIX for Dummies Questions & Answers

Using sed to substitute between quotes.

I'm using sed to perform a simply search and replace. The typical data is: <fig><image href="Graphics/BAV.gif" align="left" placement="break" I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus: <fig><image href="NEW_VALUE" align="left"... (3 Replies)
Discussion started by: Steve_altius
3 Replies

7. Shell Programming and Scripting

Use sed or gsub command

Hi there, I'm trying to write a bash script and I have some difficulties... I have multiple files, which have the following names: file_1.txt file_2.txt ... file_26.txt Within each file there is some information, like: (in the file_1.txt) name of the file: file_name_1_info.hdr (in... (4 Replies)
Discussion started by: giorgos193
4 Replies

8. Shell Programming and Scripting

Using sed to substitute first occurrence

I am trying to get rid of some ending tags but I run into some problems. Ex. How are you?</EndTag><Begin>It is fine.</Begin><New> Just about I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>) I tried the following sed... (2 Replies)
Discussion started by: quixoticking11
2 Replies

9. Shell Programming and Scripting

Using SED to substitute between two patterns.

Hi All, I'm currently using SED to make various changes to some .xml files I'm working on, but I'm stuck on this particular problem. I want to remove '<placeholder>element-name</placeholder>' from the following: <heading>Element <placeholder>element-name</placeholder> not... (2 Replies)
Discussion started by: Steve_altius
2 Replies

10. UNIX for Dummies Questions & Answers

sed substitute situation

I am having a problem executing a sed substitute in a file. I have tried alot of different things I found in previous posts, however non seem to work. I want to substitute this in $FILE: VALUE=33.4 In the script I have tried the following: prev=$(awk -F"=" '{ print $2 }' $FILE ) new=$(echo... (16 Replies)
Discussion started by: newbreed1
16 Replies
Login or Register to Ask a Question