Help me add [] to my SED command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me add [] to my SED command
# 1  
Old 08-30-2012
Help me add [] to my SED command

I am trying to replace various punctuation with spaces using SED.

Here is my current code
Code:
sed 's/[[]-=+|~!@#\$%^&*(){}:;'\'''\"''\`''\.''\/''\\']/ /g'

I need to add [] to my command so i can replace those characters as well.
I have tried adding them as []& \[\] & '\[''\]' & "\[""\]"
But nothing seems to work.

Any help is appreciated.
# 2  
Old 08-30-2012
Code:
echo 'a[bc];)x(d:ef&-y/z\r' | sed 's/[]=+|~!@#\$%^&*(){}:;.`"/-[]/ /g' | sed "s/'/ /g"

# 3  
Old 08-30-2012
for this kind of thing the best tool is tr.
# 4  
Old 08-30-2012
Quote:
Originally Posted by vgersh99
Code:
echo 'a[bc];)x(d:ef&-y/z\r' | sed 's/[]=+|~!@#\$%^&*(){}:;.`"/-[]/ /g' | sed "s/'/ /g"

I tried this but whenever there is a $ in my string (e.g. word1$word2-word3) my output looks like "word1"
# 5  
Old 08-30-2012
Code:
$ echo 'a[bc];)x(d:ef&-y/z\rword$word2-word3' | sed 's/[]=+|~!@#\$%^&*(){}:;.`"/-[]/ /g'
a bc   x d ef -y z rword word -word

# 6  
Old 09-04-2012
Here is the final code I ended up with
Code:
sed 's/[][+|~!@#\$%^&*?,><(){}:;'\'''\"''\`''\.''\/''\\'=-]/ /g'

I had to put = and - at the very end.
This User Gave Thanks to nitrobass24 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to add a new column entry

My input file looks like this 12 3 5.122.281.413 172.31.15.220 3421 4133 2 2 1454 3421 4133 2 2 0 12 44036 214.215.52.146 90.123.245.211 2312 3911 4 4 521 2312 3911 4 4 1 14 504 6.254.324.219 192.61.27.120 4444 5611 7 5 1415 4444 5611 7 5 1 ... (2 Replies)
Discussion started by: sampitosh
2 Replies

2. Shell Programming and Scripting

sed command to add special character (')

I have a file (input) which contains are below. Member Analytics Engine Enterprise Manager Dev Tutorial I want to change contains as below by using sed command 'Member Analytics Engine'; 'Enterprise Manager'; 'Dev Tutorial'; First, I tried to add (') on every first line by using sed... (8 Replies)
Discussion started by: anshu ranjan
8 Replies

3. UNIX for Dummies Questions & Answers

Output of sed command to another sed command

Hi All, I'm relatively new to Unix scripting and am trying to get my head around piping. I'm trying to take a header record from one file and prepend it to another file. I've done this by creating several temp files but i'm wondering if there is a cleaner way to do this. I'm thinking... (10 Replies)
Discussion started by: BigCroyd
10 Replies

4. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

5. Shell Programming and Scripting

How to add a line to the end of a set of files without using sed command?

I understand that the SED command reads all the lines in the file before adding a required line to the end of the file. Is there another command that adds a line to the end of files without reading the entire file.... SED is increasing the processing time as the number of lines in each of the... (1 Reply)
Discussion started by: Kanch
1 Replies

6. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

7. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

8. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies

9. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

10. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies
Login or Register to Ask a Question