sed to get rid of unwanted characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to get rid of unwanted characters
# 1  
Old 09-16-2014
sed to get rid of unwanted characters

so i have strings such as this:

Code:
'postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#'


i need to get rid of the "#" and the numbers between them for each of the strings above. so the desired output should be:

Code:
'postfix/local|CRON.*12062.*root.*CMD|roice.*NQN1|toysprc'

i tried the following:

Code:
echo 'postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#' | sed 's_#.*&#__g'

echo ''postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#' | sed 's_#&#__g'

# 2  
Old 09-16-2014
Try:
Code:
echo 'postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#' | sed 's_#[^#]*#__g'

This User Gave Thanks to Don Cragun 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

Stripping unwanted characters in field

I wrote myself a small little shell script to clean up a file I have issues with. In particular, I am stripping down a fully qualified host/domain name to just the hostname itself. The script works, but from a performance standpoint, it's not very fast and I will be working with large data sets. ... (4 Replies)
Discussion started by: dagamier
4 Replies

2. Shell Programming and Scripting

get rid of unwanted lines

Hi , My output contains the below contents When i execute df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' i get output as below tpshghghg.fgh.com:/vol/scmvol1/scm-vobstore/WebArch.vbs 1.7T 1.3T 452G 74% /vob/WebArch... (6 Replies)
Discussion started by: ptappeta
6 Replies

3. Shell Programming and Scripting

Getting rid of abnormal Characters

ok, so i have no clue why this script i wrote spits out these bizarre characters: i cant even copy and paste those characters on here because it just doesn't show up properly. my question is, using sed, how can i get rid of all characters that aren't normal? echo "abnormal characters" |... (4 Replies)
Discussion started by: SkySmart
4 Replies

4. IP Networking

How do delete unwanted characters from lsof?

Hi. I need to trace on Unix level number of connections to an Oracle database. The listener runs on port 1521. The following is run: oracle@server03 >lsof -Pni |grep ".1521" |grep IPv4 | awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1 87 IPv4 oracle@server03 > I need to append... (2 Replies)
Discussion started by: grigorianvlad
2 Replies

5. Shell Programming and Scripting

Getting rid of non-numeric and non-characters

I have a database script that always produces the following output: 0 btw, the unwanted character looks like a square on a unix system. it doesn't look like the above quote. how can I get rid of it and only keep the "0"? ---------- Post updated at 01:57 PM ---------- Previous update was... (2 Replies)
Discussion started by: SkySmart
2 Replies

6. UNIX for Dummies Questions & Answers

Need help getting rid of bold characters

Hi! So i've got this shell script that asks questions and the user is required to input answers. The answers typed are bold. sh-*.*$ sh filename dir cat question tput bold read ans tput sgr0 ... and so on tput sgr0 exit So when the script ends i don't get the bold characters... (3 Replies)
Discussion started by: Kingzy
3 Replies

7. Shell Programming and Scripting

removing unwanted characters from a file

i have a file like this 1111_2222#$#$dudgfdk 11111111_343434#$#$334 1111_22222#43445667 i want to remove all those charachetrs from # how can i do this Thank in advance Saravanan (4 Replies)
Discussion started by: saravanan71184
4 Replies

8. Shell Programming and Scripting

to replace unwanted new line characters

Hi how to replace un wanted new line characters. my file contains data like. ramu,sony,"raju \n ravi \n ramya" \n ravi,sarah,"sowmya \n sorry s\ sangam" \n i want replace new line characters in between double coats with single space. for example $ cat input_file ramu,sony,"raju... (3 Replies)
Discussion started by: Raghava
3 Replies

9. UNIX and Linux Applications

get rid of special characters

Hi Friends, we have recently installed RHEL4.4 and when i give the commd ls -l > tt it prints the file name with some special charactes like ^[[00m1 in the begining of the file name and at the end of the file name. I wanted to use the file names of removing it before taking the backup and... (4 Replies)
Discussion started by: vakharia Mahesh
4 Replies

10. UNIX for Dummies Questions & Answers

Diff output, unwanted characters

I've got a diff command running in a shell script that writes the ouput to a new file. In the new file there is a ">" at the beginning of each line. The output file is going to be used by another program and that character makes the file useless. What I'm getting in the new file: > 2007-09-27... (5 Replies)
Discussion started by: scanner248
5 Replies
Login or Register to Ask a Question