Visit Our UNIX and Linux User Community


sed replace encoded string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed replace encoded string
# 1  
Old 01-09-2008
sed replace encoded string

I'm trying to replace the string %2d from a text file using sed, and I can't seem to find the right key combination. I've tried:

sed 's/%2d/-/' foo

The above doesn't work, presumably because of the %. Smilie Interestingly, I don't get any kind of error message at all. It appears to succeed, but when I vi the file, the %2d string is still present throughout the file. Can anyone help me figure out which magic phrase to invoke here?

Thanks! Smilie
# 2  
Old 01-09-2008
pipe the output to a new file. or use -i option if your sed supports it.
# 3  
Old 01-10-2008
Quote:
It appears to succeed
Did you confirm the above from the output in stdout ?

If so, use solution as suggested by ghostdog Smilie
# 4  
Old 01-10-2008
Sorry, I'm a little new at this, and don't know how to use stdout. However, to clarify, it seems to be replacing the first instance of the string in each line it encounters, but if there's more than one ocurrence in the line, the remaining iterations are not removed. For example, I've got a test.txt file with the following line:

AF%20Form%20931%20Performance%20Feedback%20Worksheet(AB%20thru%20TSgt).xfdl

When I run test.txt through the following command: sed 's/%20/ /' test.txt > test2.txt

It becomes this:

AF Form%20931%20Performance%20Feedback%20Worksheet(AB%20thru%20TSgt).xfdl

How do I get the sed command to remove all ocurrences in the file?

And, to answer your question, -i isn't supported in my version. I got an illegal option when I tried to use it:

sed -i 's/%20/ /' test.txt > test2.txt
sed: illegal option -- i
# 5  
Old 01-10-2008
Code:
sed 's/%20/ /g' test.txt > test2.txt

Smilie
# 6  
Old 01-10-2008
It worked!! THANK YOU THANK YOU

Smilie Wahooo! That worked! Thanks so much!

(Such a simple solution, I feel silly now Smilie).
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #532
Difficulty: Medium
UTF-8 uses a fixed number of bytes to encode characters.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to replace string

Hello guys, I'm working in a cellular company and i'm trying to do a script to run some commands automaticlly. I'm using Solaris version :SunOS pk-ercuas4 5.10 in my work. I've a file that creates by script named test1.mos that that look like: confb+ gsg+ lt all $date = `date... (1 Reply)
Discussion started by: oferg
1 Replies

2. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

5. Shell Programming and Scripting

Base 64 encoded string

Could anyone of you please give me some idea to decode base 64 encoded value in ksh? (4 Replies)
Discussion started by: nram_krishna@ya
4 Replies

6. Shell Programming and Scripting

Sed - replace in the string

I have problem with replacement text. For example I have text in the file: <first> <first> <ex> <first> <first> </ex> <first> <first> I need replace all <first> only between </ex> using sed. Thank you for your reply (8 Replies)
Discussion started by: tomix
8 Replies

7. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

10. UNIX for Dummies Questions & Answers

Is it possible to replace more the 1 string with one SED?

i want to replace two phrases in text file originalstringA.1. blah blah.... originalstringB.1. got this code so far: #variables IP=$1 NO=$2 FS=$3 IS=$4 NN=1 #echo variables echo '' echo $IP echo $NO echo $FS echo $IS (1 Reply)
Discussion started by: tuathan
1 Replies

Featured Tech Videos