Find and Remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and Remove
# 1  
Old 09-06-2011
Find and Remove

I am trying to get multiple strings removed or replaced with space in a file, for individual strings I have been using the following and it works
Code:
sed -e 's/#*#*//g' test_1.dat > test_2.dat

what needs to be done if multiple strings are to be removed?


For example I will need to remove the following strings
1. #*#*
2. *#*#
3. !!@!#
4. &*(%(


Rather than have 4 different commands to do this, I would like to get the result in one command. The reason why I have to have it done in one line is because the above command will be used to replace a set of strings from over 200 files; I am planning to create a generic script that will have the set of strings to be removed or replaced.




Thanks.

Last edited by Franklin52; 09-07-2011 at 03:30 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 09-06-2011
Hi,
Try this,
Code:
sed -e 's/[*@#!]*//g'

Cheers,
Ranga:-)

Last edited by Franklin52; 09-07-2011 at 03:31 AM.. Reason: Please use code tags for code and data samples, thank you
# 3  
Old 09-06-2011
1. #*#*
2. *#*#
3. !!@!#
4. &*(%(

what does the "*" in your strings mean?
it means "*" itself?
or has the meaning of "*" in RegularExpression context?
or indicating a wild cast (any characters)?
# 4  
Old 09-06-2011
Thanks @ rangarasan it did work.

used
Code:
sed -e 's/[#*#*]*[*#*#]*[!!@!#]*[&*(%(] //g' test_1.dat > test_2.dat

@ sk1418
the "*" in the string provided is "*" and not wild cast.

Thanks.

Last edited by Franklin52; 09-07-2011 at 03:31 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Dummies Questions & Answers

Using find with awk to remove newlines

I want to list all html files present in a directory tree, the remove the newline and get one string with a space between files find /home/chrisd/Desktop/seg/geohtml/ -name '*.html' | awk BEGIN{FS=\r} '{print}' ---------- Post updated at 06:47 PM ---------- Previous update was at 06:25 PM... (5 Replies)
Discussion started by: kristinu
5 Replies

3. Shell Programming and Scripting

Remove ./ from result when i do find

Hi All, When i do find command i am getting result which append ./ before the file name. For example if i am trying to search aaa.txt in current directory i am using find like this: $ find . -name aaa.txt result: ./aaa.txt Now i want to remove "./" from the file name. Can some body... (5 Replies)
Discussion started by: VasuKukkapalli
5 Replies

4. Shell Programming and Scripting

Find and remove some line

hello im working on shell script to search conf file. if it find special pattern change it. like: #send_value=0 change it to send_value=1 (remove # and replace 0 with 1) how can i find and replace character on file? (1 Reply)
Discussion started by: nimafire
1 Replies

5. Shell Programming and Scripting

Find and Remove rows

******************************************* * ROW * ******************************************* CODE:CODE1 FILE: FILE1 FIELD: FIELD1 KEY: KEY1 ORA-00001: unique constraint (ETL.KEY_PK) violated ******************************************* * ROW * *******************************************... (7 Replies)
Discussion started by: Shanks
7 Replies

6. Shell Programming and Scripting

find regex and remove #

hi , how do i remove # from a line where i found regex.. don't need to remove all the line.. only remove comment.. (3 Replies)
Discussion started by: Poki
3 Replies

7. UNIX for Dummies Questions & Answers

Find and remove command - can you tell me exactly what its doing?

find /app01/tomcat_local -name *jsp* -type f -exec rm -r {} \; I would assume the above is just deleting any *jsp* below the /app01/tomcat_local directory - is this correct as its seems to delete more than I expect.... (1 Reply)
Discussion started by: frustrated1
1 Replies

8. UNIX for Dummies Questions & Answers

FIND and REMOVE HELP NEEDED!!!

Hello, I am aware of that Find command finds certain files and remove command removes certain files. However, is there a way to Find certain DIRECTORY and remove that DIRECTORY? thank you (3 Replies)
Discussion started by: scooter17
3 Replies

9. UNIX for Dummies Questions & Answers

Find and Remove help needed!!!!

thank you for the help. (1 Reply)
Discussion started by: scooter17
1 Replies

10. UNIX for Dummies Questions & Answers

find, remove, and ftp......

I have a script that is run each night by cron. This script generates an extract then places it into an 'extracts' folder and also ftp's a copy to another server. I have set up the script to remove any files in the extracts folder greater than 28 days old (this occurs each time the script is... (1 Reply)
Discussion started by: peter.herlihy
1 Replies
Login or Register to Ask a Question