sed command for removing symbols


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed command for removing symbols
# 1  
Old 01-24-2013
Ubuntu sed command for removing symbols

Hi I am trying to remove all the symbols in a file (testfile1) and using the below command to do that. Its not working for me. Can you help me on what is wrong with below script?
I want to retain only alphabets in a file and remove all the symbols like *:.+= etc
sed 's/^[a-zA-Z].//g' testfile1 > testfile2
# 2  
Old 01-24-2013
Code:
 $ echo "abc123+-*&^%#@\!)(" | sed 's/[^a-zA-Z]//g'
abc

# 3  
Old 01-24-2013
Ubuntu

Quote:
Originally Posted by itkamaraj
Code:
 $ echo "abc123+-*&^%#@\!)(" | sed 's/[^a-zA-Z]//g'
abc


I wanted it to be generic. Meaning to remove all the symbols.
I was able to figure it out with the below script
sed 's/[^a-zA-Z]//g' testfile1 > testfile2

But the above command removes the space also. Smilie Is there any way where I can skip alphabets as well as space?
# 4  
Old 01-24-2013
give space

Code:
sed 's/[^a-zA-Z ]//g'

# 5  
Old 01-24-2013
Ubuntu

Quote:
Originally Posted by itkamaraj
give space

Code:
sed 's/[^a-zA-Z ]//g'

Great! This worked. Thanks a lot Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Removing unwanted symbols with sed

I would like produce blue, green, red, yellowfrom"blue:,*green:,*red:,*yellowI can remove the colon with echo "blue:,*green:,*red:,*yellow" | sed 's/://g'which givesblue,*green,*red,*yellowbut when I try echo "blue:,*green:,*red:,*yellow" | sed 's/://g'; 's/*//g'I get bash: s/*//g: No such... (9 Replies)
Discussion started by: Xubuntu56
9 Replies

2. Shell Programming and Scripting

Sed, how replace specific symbols between two patterns

I have a big xmltv file with many lines like: <?xml version="1.0" encoding="UTF-8"?> <tv> <channel id="channel 1 +3HD"> <display-name lang="it">channel +3HD</display-name> <icon src="http://mywebsite.com/dsgbnjfdc65657/channel +3HD.png" /> ... (8 Replies)
Discussion started by: Tapiocapioca
8 Replies

3. Answers to Frequently Asked Questions

How to prevent sed command removing whole line?

hello, I'm using sed command to extract the text between 2 special characters which are /* and */ I used following command to do this. sed -n '/\/\*/,/\*\//p' file.txt But if the file.txt contains a line something like this, a=5; /* this is a comment */ the above command... (3 Replies)
Discussion started by: beginner_99
3 Replies

4. Shell Programming and Scripting

removing the words with symbols in a file in unix

I have file like below Hi iam author <br>joseph</br> in france. I live in my home <br></br> but no food. I will play footbal <br></br> but i wont play cricket. I will read all the books <br>all fiction stories</br> i hate horror stories. I want output like below Hi iam author... (3 Replies)
Discussion started by: vinothsekark
3 Replies

5. Shell Programming and Scripting

Removing Symbols From a File like the copyright symbol

Hi guys, I have a txt file full of funny symbols like the copyright symbol and other funny ones that get in the way when trying to use sed. For example, not sure if you can read this but I have a line that looks like this: 24(9):995Â*1001 DOI: 10.1007/s11606-009-1053-2 © When I'm using... (1 Reply)
Discussion started by: joshdg
1 Replies

6. Shell Programming and Scripting

Problem with using a sed to add escape character \ before $ and ' symbols

Hi all, I've got a problem with sed. Want to use it to add escape character \ before $ and ' symbols so condition='1'$some will become condition=\'1\'\$some echo "condition='1'$some" | sed 's/\($\)/\\\1/g' is not working properly. Can somebody help me with this please? Regards,... (7 Replies)
Discussion started by: johny_be_good
7 Replies

7. Shell Programming and Scripting

SED removing CR/LF

I have a source text file that contains something like this: <start_template> bool function( void *<var_name> ) { // Blah Blah } </start_template> Following is used to remove this template from source file. template=$(sed -n -e '/<start_template>/,/<\/start_template>/{... (4 Replies)
Discussion started by: gee22
4 Replies

8. Shell Programming and Scripting

remove accents and symbols with sed

Hi, I would like to know how could I remove accentes and the symbols: º and ª of a text file with sed. Whis this command doesn't works :-( sed "s/í/i/g" filename Many thanks and sorry for my english! (7 Replies)
Discussion started by: mierdatuti
7 Replies

9. Shell Programming and Scripting

How to replace symbols by position using SED

Hi all, I need your help. For example I have string in file.txt: -x -a /tmp/dbarchive_NSS_20081204 -f 900 -l 1 2008/12/04 2008/12/04 So, I need to replace symbols from (for e.g.) position 26 till 33 with symbols which I have in file replace.txt And I have no idea how to do it. If... (1 Reply)
Discussion started by: nypreH
1 Replies

10. Shell Programming and Scripting

new lines symbols in sed?

I want to edit a huge script file using sed. How can I add the new lines symbols in the red colored places? sed -e "s/test -z "$x"/if test -z "$x" then echo -1; \n else \n/g" (1 Reply)
Discussion started by: gogogo
1 Replies
Login or Register to Ask a Question